rodant (3) [Avatar] Offline
#1
I'm playing around with field and method access modifiers and it seems to be, that the private modifier is ignored in Groovy. I can access private fields in both ways:

myObject.field
myObject.@field

The only way I see to blocked the field, at least for the first case and only at runtime, is overwriting Object getProperty(String name), but still the second version works.

Another thing, overwriting the dot-operator methods set(String name, Object object) and get(String name) only works for plain objects, if I define a Groovy class it always has the higher priority methods getProperty() and setProperty() defined. Isn't possible to hide a field or method in Groovy? I can't really imagine that.

Antonio Rodríguez Santiesteban
Mittie (397) [Avatar] Offline
#2
Re: private fields
Hi Antonio,

your observation is correct. The 'private' visibility is currently not enforced by the Groovy runtime. See also the recent discussion in user@groovy.codehaus.org.

thanks for posting
Dierk
rodant (3) [Avatar] Offline
#3
Re: private fields
Danke schön Dierk! for the fast answer.

Antonio.
rodant (3) [Avatar] Offline
#4
Re: private fields
Hello Dierk, I took a look at codehouse.org, but, may I hope that the private semantic will be supported soon? And what about the fact that get and setProperty() are always defined in a Groovy object? the dot-access methods set(...) an get(...) has no chance at all.

Antonio.
Mittie (397) [Avatar] Offline
#5
Re: private fields
I propose to relay this discussion to the Groovy mailinglist.

Dierk