Using default function implementation of interface in Kotlin

后端 未结 4 1677
没有蜡笔的小新
没有蜡笔的小新 2020-12-29 01:47

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

interface Foo {
    fun bar(): String {
        return \"baz\"
    }
}
4条回答
  •  自闭症患者
    2020-12-29 01:59

    Please see the related issue.

    There is a recommendation in the comments:

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

提交回复
热议问题