【发布时间】:2018-03-13 20:19:56
【问题描述】:
我在Kotlin: Object 文档中找到了一个示例:
open class A(x: Int) {
public open val y: Int = x
}
interface B {...}
val ab: A = object : A(1), B {
override val y = 15
}
所以我用更有意义的名称实现了该示例,但我不知道逗号分隔的超类型列表与对象之间的接口的原因是什么?
interface Toy {
fun play () {
println("Play, play....")
}
}
open class Ball(public open val color: String = "red") {}
val ball: Ball = object : Ball(), Toy {
override val color : String = "blue"
override fun play() {
println("Bounce, bounce...")
}
}
fun main(args: Array<String>) {
println(ball.color)
// no ball.play() here then why the interface in the example ???
}
【问题讨论】:
标签: object inheritance interface kotlin delegation