Using a modifier really suppresses property creation. What confuses you is that . it seems that he refuses access to the field when such a property does not exist.
$ groovysh
Groovy Shell (2.1.0, JVM: 1.7.0_21)
Type 'help' or '\ h' for help.
-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ----------------------------
groovy: 000> class A {def a = "foo"};
===> true
groovy: 000> new A (). getA ()
===> foo
groovy: 000> new A (). a
===> foo
groovy: 000> new A (). properties
===> {class = class A, a = foo}
But:
groovy: 000> class A {public def a = "foo"};
===> true
groovy: 000> new A (). getA ()
ERROR groovy.lang.MissingMethodException:
No signature of method: A.getA () is applicable for argument types: () values: []
Possible solutions: getAt (java.lang.String), grep (), grep (java.lang.Object), with (groovy.lang.Closure), putAt (java.lang.String, java.lang.Object), wait ()
at groovysh_evaluate.run (groovysh_evaluate: 2)
...
groovy: 000> new A (). a
===> foo
groovy: 000> new A (). properties
===> {class = class A}
Artefacto
source share