我是 Kotlin 的真正 n00b 并且刚刚开始使用它的demo。
问题解决方案很简单,但有一个错误
private fun assertEquals<T>(actual : T?, expected : T?, message : Any? = null) {
if (actual != expected) {
errors++
println("Test failed")
val trace = Thread.currentThread()?.getStackTrace()!!
if (trace.size > 6) {
// Finding relevant stack frames
val location = trace.getFrameAfter("runs.Tester", "expect") // ERROR HERE
val function = trace.getFrameAfter("runs.TesterRunner", "forFunction") // AND HERE
println("at ${function?.getClassName()}.${function?.getMethodName()}(line:${location?.getLineNumber()})")
}
if (message != null)
println(message)
}
else if (!skipSuccessful)
println("OK")
}
我不明白。它说
Type mismatch: inferred type is kotlin.Array<java.lang.StackTraceElement> but
kotlin.Array<java.lang.StackTraceElement?> was expected
我既无法推断前者是如何推断的,也无法预期后者。特别是我不明白两个这样的假设来自一个方法调用。
我通过删除有问题的行来“修复”它,但我相信有人可以启发我。