Kotlin:从类对象获取超类-对象推断错误

Kotlin:从类对象获取超类-对象推断错误,kotlin,Kotlin,下面的代码应该遍历所传递对象类的超类链,直到到达顶层 protected fun getBestMethodFor(o: Any): Method? { val nodeClass = o.javaClass val objectClass = Any::class.java ... // Go through superclasses. var c = nodeClass while (c != objectClass && a

下面的代码应该遍历所传递对象类的超类链,直到到达顶层

protected fun getBestMethodFor(o: Any): Method? {
    val nodeClass = o.javaClass
    val objectClass = Any::class.java
    ...

    // Go through superclasses.
    var c = nodeClass
    while (c != objectClass && ans == null) {
        debugMsg("Looking for class match for " + c.name)
        ...
        c = c.superclass
    }
    ...
}
这将导致两个错误:

Error:(57, 17) Kotlin: Type mismatch: inferred type is Class<in Any!>! but Class<Any> was expected
Error:(57, 19) Kotlin: Type inference failed. Expected type mismatch: inferred type is Class<in Any!>! but Class<Any> was expected
错误:(57,17)Kotlin:类型不匹配:推断的类型是类!但上课是意料之中的
错误:(57,19)Kotlin:类型推断失败。预期类型不匹配:推断类型为类!但上课是意料之中的
为什么会失败,我需要做什么改变来解决这个问题

注意:代码是使用IntelliJ的转换器从Java自动转换而来的。

在Java中,返回