在 Kotlin 中同时扩展和实现 [英] Extend and implement at the same time in Kotlin

查看:25
本文介绍了在 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

推荐答案

interface 之间没有语法差异实现类继承.只需在冒号后以逗号分隔列出所有类型 : 如下所示:

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 MySuperClass
interface MyInterface

class MyClass : MySuperClass(), MyInterface, Serializable

禁止多类继承,一个类可以实现多个接口.

Multiple class inheritance is prohibited while multiple interfaces may be implemented by a single class.

这篇关于在 Kotlin 中同时扩展和实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆