Avatar ·

Kotlin: how to make a public getter but private setter for a property?

Hi! I've just started learning Kotlin and I'm switching from Java. In Java, I'm used to making fields with a private setter and public getter, for example: ```java private String name; public String getName() { return name; } private void setName(String name) { this.name = name; } ``` But in Kotlin, I see that properties (var) automatically create both a getter and a setter. If I write `var name: String`, both the getter and setter become public. And if I use `val name: String`, the property is read-only — there's no setter at all. I need the property to be readable from anywhere (public getter), but its value should only be changeable inside the class (private setter). How do I do this correctly in Kotlin? I tried writing `private var name: String`, but then the getter also becomes private.