简体   繁体   中英

Why T::class.java is Class<out Int> in Kotlin?

I define a class,It like this

class ResponseHandler<T : Any>(
    val typeClass: Class<out Int> = T::class.java,
    val start: () -> Unit = {},
    val success: (result: SuccessInfo<T>) -> Unit,
    val complete: () -> Unit = {}){/*...*/}

but why type of [T::class.java] is

   Class<out Int>

What i should do if i want to get the class of T ?

for example:

ResponseHandler<User>(....).typeClass is User,not Int.

There are two ways to get class of generic T :

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM