
Protected get() = 0 // No need in `protected` here. Getter visibility of var and val property should be exactly the same to the visibility of the property, thus you can only explicitly duplicate the property modifier, but it is redundant: protected val x: Int The rules about property accessors visibility modifiers are the following: If you only want to have a get method in public access - you can write this code: var isEmpty: Booleanĭue to the private modifier near the set accessor you can set this value only in methods inside your object.

If you want to get access to the field's value in a getter or setter you can use the reserved word field for it: val isEmpty: Boolean For more understanding of getters/setters in Kotlin: the two code samples below are equal: var someProperty: String = "defaultValue"Īnd var someProperty: String = "defaultValue"Īlso I want to point out that this in a getter is not your property - it's the class instance. When you try to get your object's isEmpty property you call the get method in real. In your case the private access modifier is redundant - isEmpty is private by default and can be accessed only by a getter.


It is equal to the following Java code: private final Boolean isEmpty Getters and setters are auto-generated in Kotlin.
