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
:
extension
mechanism like Jackson does in it's TypeRefference class
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.