kotlin - Why can't I get the class of a generic parameter? -
i have function takes 1 argument of generic type , want access class of it:
fun <t> test(t: t) { t::class } this fails "expression in class literal has nullable type". that's ok, understand (i use any? t , null value).
if change guaranty t not-null still fails same error message:
fun <t> test(t: t) { t!!::class } in case can t!!::class still cause trouble?
there way class without using (or casting any)?
change type indicate not-nullable , should work. can indicating t needs extend any (rather any?).
fun <t : any> test(t: t) { t::class }
Comments
Post a Comment