Feature | Java | Groovy | JavaFx |
---|---|---|---|
Varargs |
class Person { public void greet(Object... args) {   // access the "args" array here } } note: works on JDK5+ |
class Person { public void greet(Object... args) {   // access the "args" array here } } note: works on JDK5+ class Person { public void greet(Object[] args) {   // access the "args" array here } } note: any array type will do only if it is the last parameter defined. Works on JDK4+ |
Not supported |
Annotations |
@NotNull String field; |
@NotNull String field; note: annotations work in the same way as in Java, with the caveat that they can not be defined in Groovy yet, requires JDJ5+ update: Groovy 1.6 allows defining annotations in Groovy ![]() |
Not Supported |
Generics |
class MyComparable implements Comparable<MyClass> { } Map<String,Integer> map = new HashMap<String,Integer>(); |
class MyComparable implements Comparable<MyClass> { } Map<String,Integer> map = new HashMap<String,Integer>(); note: generics work in the same way as in Java, requires JDK5+ |
Not Supported |
Static imports |
import static java.awt.Color.RED; |
import static java.awt.Color.RED; note: static imports work in the same way as in Java, requires JDK5+ |
Not Supported |
Typesafe Enums |
enum Lang { JAVA, GROOVY, JAVAFX; } |
enum Lang { JAVA, GROOVY, JAVAFX; } note: enums work in the same way as in Java, plus they receive some extra behavior from the GDK |
Enum definition is not supported, but you can access them as any regular Java class, requires JDK5+ |
Enhanced for-loop |
for( Type variableName : Iterable ) // statements } |
for( Type variableName : Iterable ) // statements } Groovy has its own enhanced for loop syntax too for( Type variableName in Iterable ) // statements } note: a type must be defined in the first version (requires JDK5+), type is optional in the second version |
JavaFx has its own enhanced for loop syntax, can chain sequences for (album in albums, track in album.tracks) { if (album.title == track) // do x else // do y } it also accepts filters (with a where clause) |
Autoboxing/Unboxing |
int i = Integer.valueOf(10); Integer j = 42; |
Everything in Groovy is an object. Still it will perform autoboxing/unboxing when calling Java code that requires either a primitive or a wrapper value. | JavaFx does not have primitive types per se, rather they are called basic types: String, Boolean, Number, Integer, Duration (Basic Types table) |
Clearly Groovy has a better integration with Java the language than JavaFx does, but I must remind you that is by design of both languages. Developers that find themselves comfortable enough with Java5 features should feel right at home should they decide to pick Groovy, those who choose JavaFx will find themselves relearning new ways to do what they are used to, which is not really a bad thing per se, just beware of the context switching when programming in 2 or 3 languages that sport considerable differences feature wise and syntax wise.