Nikky
09/29/2021, 10:36 AMinline fun <reified T: FeatureSet> get(clazz: KClass<T> = T::class): T?
when i call it like so val a: Any? = foo.get()
i get the class FeatureSet
which is abstract
is there any way to forbid this syntax other than crashing at runtime ?rtsketo
09/29/2021, 10:44 AMFeatureSet
that means foo is FeatureSet also, right?Nikky
09/29/2021, 10:58 AMClassSet
although that should be irrelevant for the type inference herertsketo
09/29/2021, 11:14 AMinline fun <reified T: FeatureSet> get(clazz: KClass<T> = T::class): T?
or
inline fun <reified T: FeatureSet> T.get(clazz: KClass<T> = T::class): T?
If it's the first one as you typed, where does T get evaluated in foo.get()
?Nikky
09/29/2021, 11:32 AMinline fun <reified T: Any> get(): KClass<T> = T::class
cannot be called without type parameter, because type inference fails
if the signature changes to these however..
inline fun <reified T: Any> get(): T
inline fun <reified T: Any> get(): T?
it seems like you can call it anyways (and it passes a wrong?T
)
it is the former
T is getting evaluated via T::class
but .. does that affect the type inference ?Nikky
09/29/2021, 11:35 AMResult<T>
or any other wrapping things also help.. but i'd prefer to not create unneccesary wrapping objects just to have type inference work this way..