Extend and implement at the same time in Kotlin

2019-02-11 10:15发布

问题:

In Java, you can do such thing as:

class MyClass extends SuperClass implements MyInterface, ...

Is it possible to do the same thing in Kotlin? Assuming SuperClass is abstract and does not implement MyInterface

回答1:

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.



标签: java kotlin