Is there any chance of resurrecting the `$backingField` syntax (even if a character other than `$` is used)? The new `field` scheme seems both more restrictive and more complicated to me.
For example, this confused me tonight:
class Message(text: String) {
val text: String
get() = ""
init {
this.text = text // ERROR: "Val cannot be reassigned"
}
}
As far as I can tell, the problem here is that a backing field hasn't been generated. Please correct me if I'm wrong. (If we replace `get() = ""` with `get() = field`, it compiles fine.)
This issue wouldn’t have occurred when we could say say $text = text
, which avoids the confusion entirely.
Another example of how the new scheme can be confusing:
class Message(text: String) {
var text: String
get() = ""
set(value: String) {
field = value
}
init {
this.text = text // ERROR: "This property has a custom setter, so initialization using backing field required"
}
}
I think the old way would have been `$text = text`, with no confusion or error message.
I keep seeing arguments in favour of the $backingField
syntax. It seems unfortunate that it was dropped.