July 2013
Intermediate to advanced
370 pages
8h 27m
English
We’ve installed Groovy and checked the version—it’s time to take it for
a test-drive. Using the command-line tool groovysh is one of the quickest ways to play with Groovy. Open a terminal window,
and type groovysh; we’ll see a shell, as shown
next. Type some Groovy code to see how it works.
| | > groovysh |
| | Groovy Shell (2.1.1, JVM: 1.7.0_04-ea) |
| | Type 'help' or '\h' for help. |
| | ------------------------------------------------- |
| | groovy:000> Math.sqrt(16) |
| | ===> 4.0 |
| | groovy:000> println 'Test drive Groovy' |
| | Test drive Groovy |
| | ===> null |
| | groovy:000> String.metaClass.isPalindrome = { |
| | groovy:001> delegate == delegate.reverse() |
| | groovy:002> } |
| | ===> groovysh_evaluate$_run_closure1@64b99636 |
| | groovy:000> 'mom'.isPalindrome() ... |
Read now
Unlock full access