Conclusion

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

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
Download course materials from Github
Previous: Demo Next: Quiz: Use Properties