Issue
I use reified generics to capture KClass<>
inline fun <reified T> register(generator: Generator<T>) {
register(T::class, generator)
}
But KType
has some additional properties which are interesting to me like nullability. I would like to write something like this to capture the KType
instead.
inline fun <reified T> register(generator: Generator<T>) {
register(T::ktype, generator) // Doesn't compile
}
...
register<String?>(myGen) // The nullability of String? is captured
Is there someway to capture KType
instead of KClass<>
?
Thanks in advance.
Solution
No, as for now, this cannot be done, there is an issue in the Kotlin issue tracker about it, currently marked as To be discussed.
You can, however, get more than just KClass<T>
from the reified type parameter using subclassing and, in particular, the technique called super type tokens.
Answered By - hotkey
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.