Backing Fields

Explanation of backing fields, when they are generated and how to access them inside custom accessors

Gabriel Shanahan
The Kotlin Primer

--

— — — — — — — — — — — — — — —

THE CURRENT VERSION OF THIS ARTICLE IS PUBLISHED HERE.

— — — — — — — — — — — — — — —

Tags: #KOTLIN FEATURE

This article is part of the Kotlin Primer, an opinionated guide to the Kotlin language, which is indented to help facilitate Kotlin adoption inside Java-centric organizations. It was originally written as an organizational learning resource for Etnetera a.s. and I would like to express my sincere gratitude for their support.

It is recommended to read the Introduction before moving on. Check out the Table of Contents for all articles.

This part can appear complicated and a little confusing, but it’s actually not — the compiler takes care of everything behind the scenes, so this part is really just FYI. Basically, this section could be condensed into the sentence “if you need to access the backing field inside an accessor, use field (i.e. field = 3 or field + 5)".

However, I think it’s useful to realize that not all properties require backing fields to be generated —…

--

--