수정자를 사용하면 실제로 속성 생성이 억제됩니다. 어떤 속성이 존재하지 않을 때 .
이 필드 액세스에서 대체되는 것처럼 보이는 것이 혼란 스럽습니다.
$ 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}
그러나 :
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}
그들은 똑같이 보일지도 모릅니다 만, Groovy는 액세스 수식 자의 존재에 의해 정의되는 프로퍼티에 대해서만 getter/setter를 생성합니다. – ubiquibacon