Great job! You saw the basics of properties while learning about classes, and now you’ve seen the more advanced features Kotlin has to offer. But there’s still a long way to go!
Properties are variables and constants that are part of a named type.
Default values can assign a value to a property within the class definition.
Property initializers and the init block are used to ensure that the properties of an object are initialized when the object is created.
Custom accessors are used to execute custom code when a property is accessed or set.
The companion object holds properties that are universal to all instances of a particular class.
Delegated properties are used when you want to observe, limit or lazily create a property. You’ll want to use lazy properties when a property’s initial value is computationally intensive or when you won’t know the initial value of a property until after you’ve initialized the object.
lateinit can be used to defer setting the value of a property reference until after the instance is created.
Extension properties allow you to add properties to a class outside the class definition, for example, if you’re using a class from a library.
See forum comments
This content was released on May 22 2024. The official support period is 6-months
from this date.
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.