July 2013
Intermediate to advanced
370 pages
8h 27m
English
Let’s start with a piece of Java code with a simple loop. We’ll first run it through Groovy. Then we’ll refactor it from Java style to Groovy style. As we evolve the code, each version will do the same thing, but the code will be more expressive and concise. It will feel like our refactoring is on steroids. Let’s begin.
Let’s start with a Java code example that’s also Groovy code, saved in a file named Greetings.groovy.
| | // Java code |
| | public class Greetings { |
| | public static void main(String[] args) { |
| | for(int i = 0; i < 3; i++) { |
| | System.out.print("ho "); |
| | } |
| | |
| | System.out.println("Merry Groovy!"); |
| | } |
| | } |
Let’s execute this code using the command groovy Greetings.groovy ...
Read now
Unlock full access