Kotlin超类列表中只能出现一个类

我遇到了拥有两个超类的麻烦。当我添加PreferenceFragment()时,收到错误消息:在超类型列表中只能出现一个类

关于如何解决此问题的任何想法?

class MyaccountFragment @Inject constructor(): BaseFragment(),PreferenceFragment() {

    override fun onCreate(savedInstanceState: Bundle?) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun onCreatePreferences(savedInstanceState: Bundle?,rootKey: String?) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun initView() {
    }

    override fun initEvent() {
    }
}

谢谢!

a19811204 回答:Kotlin超类列表中只能出现一个类

Kotlin不支持多重继承。您一次只能扩展一个课程

尝试一下

open class BaseFragment : PreferenceFragment()  {

}

class MyAccountFragment @Inject constructor(): BaseFragment(){

}
,

我发现 Multi-inheritance in Kotlin through Composition 是一个解决方案。

本文链接:https://www.f2er.com/3140588.html

大家都在问