kotlin匿名内部类与接口实现
例如:
class Test {
fun setInterface(ti: TestInterface) {
ti.test()
}
}
interface TestInterface {
fun test()
}
fun main(args: Array<String>) {
var t = Test()
t.setInterface(object : TestInterface {
override fun test() {
println("zhangphil")
}
})
}
输出: