bendb
11/08/2016, 7:44 PMT is basically equivalent to <T : Any?>. Why then is a value value: T not smart-cast to T2 such that <T2 : Any>?
The motivating example that I wanted (and which failed) was something like:
fun <T> assertIsInstanceOf(value: T, type: KClass<*>) {
if (value != null) {
assert(type.java.isAssignableFrom(value.javaClass)) // this fails to compile as 'javaClass' does not exist on `Any?`
}
}
The workaround was to declare the function fun <T : Any> assertIsInstanceOf(value: T?, type: KClass<*>), which seems to work, but feels unsatisfying. What could I be missing about generics and smart-casting?