https://kotlinlang.org logo
Title
c

CodeIsmail

10/11/2018, 8:06 PM
Hi, Can anyone explain what "backing field" is, with code sample. I'd appreciate it.
The
field
here references the backing field
var x: Int
  get() = field
  set(value) { field = value}
Not every property has a backing field. For example this one does not need it:
val y: Int get() = 3
But properties that keep their own state have to have a backing field, and it is only accessible from their getter and setter
c

CodeIsmail

10/11/2018, 8:33 PM
This has been helpful. Thank you.