• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Groovy Beans

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Am I missing something?

The concept of automagic properties is nice, but not that useful because generated methods have same permission as fields. The point of a bean/properties is to provide encapsulation. Private fields do not generate access methods. Public fields should typically be avoided.

Doc at: http://docs.codehaus.org/display/GROOVY/Groovy+Beans


class One {
private int xyz
int abc
}

class Two {
private int xyz

int getXyz() {return xyz} // not created automatically for private
void setXyz(int x) {xyz=x} // not created automatically for private
}

def o=new One()
//o.setXyz(1111)// causes exception
o.setAbc(123)// works

def t=new Two()
t.setXyz(222)


Rob.
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you may be misreading the example.

Groovy properties are declared vert much like fields but they result in private fields and public getters and setters.
 
Tug Wilson
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have made minor changes to the page and have corrected a couple of errors.

I hope you find it clearer now
 
Rob Wednesday
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your help.

I got off track in an initial test because o.xyz worked. I forgot that it was accessible because of package permissions.

Rob.
 
Hey cool! They got a blimp! But I have a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic