“无法直接访问抽象成员。”我如何克服继承接口的这个方面?

问题描述 投票:0回答:1
class meow(): InputConnection{
     override fun getTextBeforeCursor(before:Int,after:Int):CharSequence?{
       return super.getTextBeforeCursor(before,after)
     }


}

但是 whai 继承一个接口既需要覆盖,又说“不能直接访问它”? what the above errors

此图像是由此产生的错误。一个是因为有更多的东西需要覆盖(是的),另一个是如何覆盖

can't access abstract member directly
(为什么?)。

不仅仅是'为什么',而是hao正确地继承了这方面的接口?

kotlin inheritance interface overriding abstract
1个回答
0
投票

您不能调用 abstract 函数,因为它没有定义调用时要做什么。

如果一个接口声明了一个没有任何默认实现的函数,那么它就是abstract

在这种情况下,显然 InputConnection 类没有为此函数定义默认实现。

InputConnection.getTextBeforeCursor()
是抽象的,因此您不能使用
super.getTextBeforeCursor()
来调用它。

要正确执行此操作,由您定义此函数的内容及其行为方式,而不依赖于此函数的

super
版本。

© www.soinside.com 2019 - 2024. All rights reserved.