Hi Schalk,
Defining class as below is equivalent to below construction in Java:
public class A {
private String name
public String getName() {
return
this.name;
}
public void setName(String name) {
this.name = name;
}
}
Basically in Groovy if you omit access modifier when field is
concerned:
a) the field is made private
b) getter and setter is automatically generated
Additionally if you refer to field like this:
new A().name
it is just a shortcut to:
new A().getName()
To refer to field directly (not by getter) you can do sth like this:
new A().@name
however it is not recommended.
You can find more on the subject here:
http://groovy.codehaus.org/Groovy+Beans
Best regards,
Michal
W dniu 21.11.2014 o 21:43, Schalk Cronj é pisze:
> In Groovy when referring to a data member of a class such as below
>
> class A {
> String name
> }
>
> what is the preferred way of referring to 'name' ? Is it a field or a
> property?
>