Reputation: 187399
In the Groovy console, the following code executes without error:
class F {
private def getFoo() {"foo"}
private def barValue = "bar"
}
def f = new F()
assert f.barValue == "bar"
assert f.properties.containsKey("foo")
This implies that:
It seems to me that both of these are extremely severe language bugs. Although I really like Groovy, I find it incredible that a language that has been around for a reasonably long time, hasn't implemented something as fundamental as the concept of privacy correctly.
Are these actually bugs or am I missing something?
Thanks, Don
Upvotes: 2
Views: 225
Reputation: 6120
It is intentional, sadly. This changed with 1.5. Unfortunately, in order to support their mechanism for closures, and their meta-object protocol, they have to have access to private members.
This article explains a little more thoroughly: http://www.benjaminbooth.com/tableorbooth/2008/07/groovy-15-no-private-for-you.html
Upvotes: 5