Kotlin : Public get private set var

后端 未结 3 366
借酒劲吻你
借酒劲吻你 2020-12-03 02:13

What is the correct way to define a var in kotlin that has a public getter and private (only internally modifiable) setter?

3条回答
  •  既然无缘
    2020-12-03 02:56

    var setterVisibility: String = "abc" // Initializer required, not a nullable type
        private set // the setter is private and has the default implementation
    

    See: Properties Getter and Setter

提交回复
热议问题