I have a Kotlin interface with a default implementation, for instance:

interface Foo {
    fun bar(): String {
        return "baz"
    }
}

在我try 从Java实现这个接口之前,这是可以的.当我这样做的时候,它说这个类需要被标记为抽象的,或者实现方法bar().此外,当我try 实现该方法时,我无法调用super.bar().

推荐答案

Please see the related issue.

comments 中有一条建议:

Write your interface in Java (with default methods) and both the Java and Kotlin classes correctly use those defaults

Kotlin相关问答推荐

在Kotlin Jetpack中重用下拉菜单

判断字符串是否除了.&" ",","@""""

Kotlin-删除按钮周围的空格

为什么onEach不是挂起函数,而Collect是?

如何在Spring Boot中注册新的集合工厂

Java/Kotlin中类似Rust般的注释编译?

Webpack 配置未应用于 kotlin 多平台react 项目

为什么 Kotlin 在将协变类型参数转换为不变类型参数时会产生 Unchecked Cast 警告?

TzdbZoneRulesProvider 在 java.time 中不工作

Kotlin - 协程未按预期执行

在 Compose 中使用 Text() 时如何获取文本的大小?

Jetpack Compose - 单击 LazyColumn 的项目时应用程序崩溃

Kotlin 中列表或数组的乘积

有没有办法重用 Job 实例?

.indices 在 kotlin 中的含义是什么?

Kotlin:内部类如何访问在外部类中声明为参数的变量?

Kotlin 的 isNullOrBlank() 函数是否可以导入 xml 以用于数据绑定

Kotlin惰性默认属性

在java代码中使用kotlin库

如何在不绑定ViewModel(MVVM)中的UI的情况下使用android导航?