Properties of Classes

Learn how Kotlin does a better job than Java when it comes to accessing class properties.

Overview

Classes in Kotlin have properties, rather than simple fields, with implicit and automatically generated getters and setters. Calling these getters and setters does not look syntactically different than direct field access in Java.

Boilerplate code in Java

A common source of unnecessary boilerplate code in Java are getters and setters for the fields of a class:

Get hands-on with 1200+ tech skills courses.