Hi, Can anyone explain what "backing field" is, wi...
# getting-started
c
Hi, Can anyone explain what "backing field" is, with code sample. I'd appreciate it.
The
field
here references the backing field
Copy code
var x: Int
  get() = field
  set(value) { field = value}
Not every property has a backing field. For example this one does not need it:
Copy code
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
This has been helpful. Thank you.