在迁移到Kotlinfrom 时Java我遇到了一个问题。我覆盖了Object的finalize()方法:
@Override
protected void finalize() throws Throwable {
stopTimer();
super.finalize();
}
Run Code Online (Sandbox Code Playgroud)
当我尝试用 Kotlin 做同样的事情时,我找到了解决方案。第一个来自文档:
protected fun finalize() {
stopTimer()
super.finalize()
}
Run Code Online (Sandbox Code Playgroud)
文章中的第二个(俄语):
@Suppress("ProtectedInFinal", "Unused")
protected fun finalize() {
stopTimer()
super.finalize()
}
Run Code Online (Sandbox Code Playgroud)
但在这两种情况下,我都不能super.finalize()根据 IDE调用,正如它所说的unresolved reference:finalize
也许有人知道如何完成这项工作Kotlin?谢谢。