Chapter 6. Optimizing Access to Properties
Properties are class members that hold values and define rules for reading and writing those values. In Kotlin, the properties of a class represent the current state of an instance of that class. A typical class with properties looks like this:
class Button { var text: String = TODO() var backgroundColor: Int = TODO() var onClickListener: ((Button) -> Unit)? = null }
We can use this class to create objects and set values for the text
, backgroundColor
, and onClickListener
properties. A combination of these properties in one object represents the state of an instance of the Button
class.
In this chapter, we'll cover the following topics:
Fields and properties
Code inspection