-
Book Overview & Buying
-
Table Of Contents
Android Programming for Beginners - Fourth Edition
By :
Q) What is a property in a class?
A) A property is a variable that belongs to a class and represents part of the object's data. Unlike local variables, properties can have visibility modifiers, custom access rules, and automatically generated getters and setters.
Q) Do I need to write getters and setters myself?
A) Kotlin automatically generates getters for val properties and getters plus setters for var properties. You only write them yourself when you need custom behavior.
Q) What is a backing field?
A) A backing field is the hidden storage that actually holds a property's value when that property needs to store data in memory. It lets getters and setters read and write the stored value without causing infinite recursion.
Q) When does Kotlin create a backing field?
A) Kotlin creates a backing field only if it is really needed, for example, when a property uses at least one default getter/setter or when a custom getter or setter refers to the special field identifier. If...