在Kotlin中实现Java接口 [英] Implementing Java interface in Kotlin
本文介绍了在Kotlin中实现Java接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 Java 界面:
public interface NonHindiQurary {
void onNonHindiQueryReceived(String Query);
}
我想在 Kotlin 类上实现它:
class MainActivity : AppCompatActivity() {...}
问:我该怎么做?
推荐答案
很简单:
class MainActivity : AppCompatActivity(), NonHindiQuery {
override fun onNonHindiQueryReceived(q: String) {
// <...>
}
}
摆脱> c0> 从方法主体中删除TODO("not implemented")
:
To get rid of kotlin.NotImplementedError
remove TODO("not implemented")
from the method body:
@kotlin.internal.InlineOnly
public inline fun TODO(reason: String): Nothing =
throw NotImplementedError("An operation is not implemented: $reason")
这篇关于在Kotlin中实现Java接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文