Legal to use "field" for property called "field"?


Is it legal to use field for a property called field? Or would this be recursive?

var field : String = “”
get () {
return field
set(value) {
field = value

The Eclipse Kotlin plugin doesn’t seem to be working so I can’t test this out unfortunately.

No, such a property is not recursive. The “field” identifier in an accessor always refers to the backing field of a property, even if the property itself is called “field”.

Why doesn’t the Eclipse plugin work for you? What exactly is the issue?

You can use “this.field” as reference a fiel property instead a “the field”.

var field: String = ""

var foo : String = ""
   set(value) {
     field = "$value ${this.field}"

In the set, field is “foo” and this.field is “field”.