Groovy for Java Devs
Learn about the differences between Groovy and Java commands.
We'll cover the following...
Groovy vs. Java
Feature | Java | Groovy |
Public Class | public class | class |
Loops | for(Type it : c){…} | c.each {…} |
Lists | List list = asList(1,2,3); | def list = [1,2,3] |
Maps | Map m = …; m.put(x,y); | def m = [x: y] |
Function Def. | void method(Type t) {} | def method(t) {} |
Mutable Value | Type t | def t |
Immutable Value | final Type t | final t |
Null safety | (x == null ? null : x.y) | x?.y |
Null replacement | (x == null ? “y” : x) | x ?: “y” |
Sort | Collections.sort(list) | list.sort() |
Wildcard import | import java.util.*; | import java.util.* |
Var-args | (String… args) | (String… args) |
Type parameters | Class<T> | Class<T> |
Concurrency | Fork/Join | GPars |
...