Hi,
Previously I'd thought that a property in Groovy is indicated by the omission of a scoping keyword. In other words
class Test {
def prop = "i am a property"
public notProp = "i am not"
}
However, it appears I'm incorrect about this, because the following script prints "getter val"
class Foo {
public bar = "init val"
public getBar() {
"getter val"
}
}
println new Foo().bar
The fact that the getter is invoked when bar
is accessed suggests that bar
is a property rather than a field. So what exactly is the difference between fields and properties in Groovy.
Thanks, Don