Skip to content

Instantly share code, notes, and snippets.

@donglua
Last active October 20, 2016 03:37
Show Gist options
  • Save donglua/921345db5710dcd78f5b9f75a0643d3a to your computer and use it in GitHub Desktop.
Save donglua/921345db5710dcd78f5b9f75a0643d3a to your computer and use it in GitHub Desktop.
Kotlin 的构造方法参数
class MyClass
constructor(
    private val value1: Int,
    var value2: String,
    value3: Int,
)
  • 这里的 private val value1: Int表示传入参数 value1 并赋值给命名为 value1 的成员变量
  • value3 参数只在构造方法中使用
  • kotlin 会为 value1 生成 get 方法, 为 value2 生成 set 和 get 方法
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment