在Kotlin同时扩展和实施 [英] Extend and implement at the same time in Kotlin
本文介绍了在Kotlin同时扩展和实施的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Java中,你可以这样做:
In Java, you can do such thing as:
class MyClass extends SuperClass implements MyInterface, ...
是否有可能在Kotlin做同样的事情?假设 SuperClass
是抽象的并且没有实现 MyInterface
Is it possible to do the same thing in Kotlin? Assuming SuperClass
is abstract and does not implement MyInterface
推荐答案
界面实施和<之间没有语法差异a href =https://kotlinlang.org/docs/reference/classes.html#inheritance =noreferrer>类继承。只需列出以冒号:
后逗号分隔的所有类型,如下所示:
There's no syntactic difference between interface implementation and class inheritance. Simply list all types comma-separated after a colon :
as shown here:
abstract class SuperClass
interface MyInterface
class MyClass : SuperClass(), MyInterface, Serializable
禁止多类继承,而单个类可以实现多个接口。
Multiple class inheritance is prohibited while multiple interfaces may be implemented by a single class.
这篇关于在Kotlin同时扩展和实施的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文