小编Jos*_*Yan的帖子

在kotlin中,如何使主构造函数中的属性setter成为私有?

在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
    }
}
Run Code Online (Sandbox Code Playgroud)

我希望属性的setter name是私有的,并且公开的getter,我该怎么办?

constructor kotlin

10
推荐指数
1
解决办法
2783
查看次数

标签 统计

constructor ×1

kotlin ×1