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 方法
class MyClass
constructor(
private val value1: Int,
var value2: String,
value3: Int,
)
private val value1: Int
表示传入参数 value1 并赋值给命名为 value1 的成员变量