'inferred type is Class<in Any!>! but Class<Any>? was expected

Kotlin 1.3.11

fun doSomething(clazz : Class<Any>?){
    if(clazz == null){return}
    var myClass = clazz
    //processing
    myClass = clazz.superclass
    //processing
}

This will cause compilation error

Type inference failed. Expected type mismatch: inferred type is Class<in Any!>! but Class? was expected

What should be done to fix it?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source