APXEOLOG
01/07/2019, 1:41 PMval properties = mutableListOf<Property>()
inline fun <reified T : Property> getProperty(): T? {
return properties.filter { it::class == T::class }.firstOrNull() as T?
}
I don't like this as T?
part, but if i remove it i will receive error:
Type inference failed. Required: T?, found: Property?
Am i doing something wrong?gsala
01/07/2019, 1:46 PM.filterIsInstance<T>()
insteadDico
01/07/2019, 1:46 PMmapNotNull { (it as? T)?.takeIf { it::class == T::class } }
Dico
01/07/2019, 1:50 PMfind { it::class == T::class } as T?
Dico
01/07/2019, 1:50 PMas
or is
anyway.Dico
01/07/2019, 1:52 PM::class
instead of using is
check? The difference is subtle and probably not intended.APXEOLOG
01/07/2019, 1:56 PMis
check the ability to cast to? Meaning that it will also count in inherited classesDico
01/07/2019, 1:56 PMDico
01/07/2019, 1:57 PM