How to make a property in Kotlin that has a private getter (or just do not have it) but has a public setter?
var status
private get
doesn\'
In current Kotlin version (1.0.3) the only option is to have separate setter method like so:
class Test {
private var name: String = "name"
fun setName(name: String) {
this.name = name
}
}
If you wish to restrict external libraries from accessing the getter you can use internal visibility modifier allowing you to still use property syntax within the library:
class Test {
internal var name: String = "name"
fun setName(name: String) { this.name = name }
}
fun usage(){
val t = Test()
t.name = "New"
}