O'Reilly logo

Android Development with Kotlin by Igor Wojda, Marcin Moskala

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Properties

Property is just a combination of a backing field and its accessors. It could be a backing field with both a getter and a setter or a backing field with only one of them. Properties can be defined at the top-level (directly inside file) or as a member (for example, inside class, interface, and so on).

In general, it is advisable to define properties (private fields with getters/setters) instead of accessing public fields directly (According to Effective Java, by Joshua Bloch, book's item 14: in public classes, use accessor methods, not public fields).

Java getter and setter conventions for private fields Getter: A parameterless method with a name that corresponds to property name and a get prefix (for a Boolean property there ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required