Kotlin教程:定义接口与实现
接口是类的蓝图(基础框架)。Kotlin接口类似于Java 8
中的接口,它包含抽象方法声明以及方法的实现。
定义接口
接口是使用interface
关键字来定义的。 例如:
interface MyInterface {
val id: Int // abstract property
fun absMethod()// abstract method
fun doSomthing() {
// optional body
}
}