在 Kotlin 中,如何使主构造函数中属性的 setter 私有化?
class City(val id: String, var name: String, var description: String = "") {
fun update(name: String, description: String? = "") {
this.name = name
this.description = description ?: this.description
}
}
我希望将属性name
的setter设为private,getter设为public,该如何操作?