Published in: Groovy
URL: http://hansamann.podspot.de/files/grails_podcast_episode_42.mp3
This snippet gives you some interesting examples about GroovyBeans and Expando. Listen to the audio to get the best learning experience. Simply right-click on the title above to download the mp3 file of this part of the series.
The Groovy Series is part of the Grails Podcast and can be subscribed to via: http://hansamann.podspot.de/rss. The series is produced by Dierk König and Sven Haiges, further information about the topic of this episode can be found in the book
Groovy in Action - http://groovy.canoo.com/gina
//GroovyBeans are JavaBeans, just made easier. What exactly is the advantage? //simple groovybean -> note Serializable! { String myProperty } bean1.myProperty = "groovy" bean1.setMyProperty("grails") //another bean, just no "javabean" class AnotherBean { def prop1, prop2, prop3 } bean2.prop1 = "one" //access to all properties... interestingly "properties" is not a property //direct field access with .@ operator - dot at //plus example of using map constructor class HackedBean { String someValue { return "always the same" } { } } // Expando magic. dyn."$it" = it //dyn[it] = it } //it even gets better: you can assign "methods" by setting closures
You need to login to post a comment.
