miha-x64
11/19/2017, 11:15 AMsomeInlineFunc<A<X>, A<Y>, B<X>>()
, is there a way to say that first two type arguments are different?
(Okay, I've resolved my task without it, now it's just a proof-of-concept question.)snrostov
11/19/2017, 11:39 AMinline fun <reified T> typeOf(): Type? {
val token = object : TypeToken<T>() {}
return (token.javaClass.genericSuperclass as ParameterizedType).actualTypeArguments[0]
}
And there is issue in youtrack, to get type without creating anonymous class for every call.miha-x64
11/19/2017, 12:05 PMsnrostov
11/19/2017, 12:06 PMabstract class TypeToken<T>
inline fun <reified T> typeOf(): Type? {
val token = object : TypeToken<T>() {}
return (token.javaClass.genericSuperclass as ParameterizedType).actualTypeArguments[0]
}
fun main(args: Array<String>) {
println(typeOf<Int>())
println(typeOf<List<Int>>())
}
prints
class java.lang.Integer
java.util.List<? extends java.lang.Integer>
miha-x64
11/19/2017, 12:17 PM