Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Apache Groovy
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===GroovyBeans, properties=== ''GroovyBeans'' are Groovy's version of [[JavaBeans]]. Groovy implicitly generates getters and setters. In the following code, <code>setColor(String color)</code> and <code>getColor()</code> are implicitly generated. The last two lines, which appear to access color directly, are actually calling the implicitly generated methods.<ref name=konig38_9>König 2007, pp. 38-9</ref> <syntaxhighlight lang="groovy"> class AGroovyBean { String color } def myGroovyBean = new AGroovyBean() myGroovyBean.setColor('baby blue') assert myGroovyBean.getColor() == 'baby blue' myGroovyBean.color = 'pewter' assert myGroovyBean.color == 'pewter' </syntaxhighlight> Groovy offers simple, consistent syntax for handling ''lists'' and ''maps'', reminiscent of Java's ''array'' syntax.<ref name=konig41_3>König 2007, pp. 41-3</ref> <syntaxhighlight lang="groovy"> def movieList = ['Dersu Uzala', 'Ran', 'Seven Samurai'] // Looks like an array, but is a list assert movieList[2] == 'Seven Samurai' movieList[3] = 'Casablanca' // Adds an element to the list assert movieList.size() == 4 def monthMap = [ 'January' : 31, 'February' : 28, 'March' : 31 ] // Declares a map assert monthMap['March'] == 31 // Accesses an entry monthMap['April'] = 30 // Adds an entry to the map assert monthMap.size() == 4 </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)