1.写法如下:
fun main(args: Array<String>) {
val son = Son()
son sayHello "张三"
}
open class Father {
}
class Son : Father() {
}
infix fun Father.sayHello(name: String) {
println("爸爸打招呼了,你好$name")
}
- 对于扩展的函数sayHello子类不能覆写
fun main(args: Array<String>) {
val son = Son()
son sayHello "张三"
}
open class Father {
}
class Son : Father() {
}
infix fun Father.sayHello(name: String) {
println("爸爸打招呼了,你好$name")
}
本文标题:53.扩展父类函数,子类调用
本文链接:https://www.haomeiwen.com/subject/oqhepctx.html
网友评论