Why can't I get the class of a generic parameter?

Viewed 7808

I have a function which takes one argument of a generic type and I want to access the class of it:

fun <T> test(t: T) {
    t::class
}

This fails with "expression in class literal has nullable type". That's ok, I understand it (I could use Any? as my T and null as the value).
But if I change it to guaranty that t is not-null it still fails with the same error message:

fun <T> test(t: T) {
    t!!::class
}

In which case can t!!::class still cause trouble?
Is there a way to get the class without using Any (or casting to Any)?

3 Answers
Related