logo
  • 教程列表
  • SO官方文档
  • 类代表团
    • 将方法委托给另一个类
  1. StackOverflow 文档
  2. Kotlin 教程
  3. 类代表团
  4. 将方法委托给另一个类

将方法委托给另一个类

Created: November-22, 2018

interface Foo {
    fun example()
}

class Bar {
    fun example() {
        println("Hello, world!")
    }
}

class Baz(b : Bar) : Foo by b

Baz(Bar()).example()

该示例打印 Hello, world!

  • 类代表团

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 关于我们
  • 免责声明