How to disable the generation of Groovy accessories?

Groovy Beans are great, but I'm just wondering if it's possible to declare a class member private and not easy to create accessors for it? The page http: // groovy.codehaus.org/Groovy + Beans> Groovy Beans does not cover this topic. The only thing I can think of is to identify accessors and make them private.

+6
groovy
source share
1 answer

Groovy will not add accessors if a member is declared with an access modifier: private, secure, or public. If you don’t need accessors, just add a suitable modifier. Here is an example that illustrates this:

class Test1 { private int blat } println Test1.metaClass.getMethods()*.name.findAll { it.endsWith("Blat") } class Test2 { protected int blat } println Test2.metaClass.getMethods()*.name.findAll { it.endsWith("Blat") } class Test3 { public int blat } println Test3.metaClass.getMethods()*.name.findAll { it.endsWith("Blat") } class Test4 { int blat } println Test4.metaClass.getMethods()*.name.findAll { it.endsWith("Blat") } 

Print

 [] [] [] [getBlat, setBlat] 
+10
source share

All Articles