java - 在 Kotlin 中同时扩展和实现

在 Java 中,您可以执行以下操作:

class MyClass extends SuperClass implements MyInterface, ...

在 Kotlin 中可以做同样的事情吗?假设 SuperClass 是抽象的并且没有实现 MyInterface

最佳答案

interface implementation 之间没有语法差异和 class inheritance .只需在冒号 : 后列出所有以逗号分隔的类型,如下所示:

abstract class MySuperClass
interface MyInterface

class MyClass : MySuperClass(), MyInterface, Serializable

禁止多类继承,一个类可以实现多个接口(interface)。

https://stackoverflow.com/questions/48391217/

相关文章:

kotlin - Kotlin 中的 crossinline 和 noinline 有什么区别?

java - 在 Kotlin 中定义 log TAG 常量的最佳方法是什么?

java - 如何将 Java 源文件的一部分转换为 Kotlin?

android - Kotlin - 将 List 转换为 MutableList 的最惯用方式

generics - kotlin 中的 out 关键字是什么

kotlin - 如何在 Kotlin 中迭代 hashmap?

java - 将 Kotlin 数据对象映射到数据对象的更好方法

dictionary - Kotlin 是否有 Map 文字的语法?

kotlin - 在 Android Studio 中构建时如何解决错误 "Failed to re

kotlin - 如何在 Kotlin 中写入文件?