Groovy Beans are great but I'm just curious if it's possible to declare a class member private and not generate accessors for it easily? The http://groovy.codehaus.org/Groovy+Beans>Groovy Beans page doesn't cover this topic. The only thing that I can think of would be to define the accessors and make them private.
Groovy won't add accessors if the member is declared with an access modifier: private, protected or public. If you don't want accessors, just add whichever modifier is appropriate. Here's 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") }
Prints:
[]
[]
[]
[getBlat, setBlat]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With