is there any way to get a smart cast for a situati...
# announcements
b
is there any way to get a smart cast for a situation like this so i can avoid the complaint about unchecked cast/having to supress it?
Copy code
class Foo<T : Any>(private val valueType: KClass<T>) {
    fun getThing(): T {
        return when (valueType) {
            // complains here: "Type mismatch, required T found Int" unless I add "as T" at the end
            Integer.class -> functionThatReturnsInt()
            Double.class, etc....
        }
    }
}