July 2013
Intermediate to advanced
370 pages
8h 27m
English
Java 5 language features like enums and annotations work in Groovy also. This means we can mix Java and Groovy quite fluently. To refresh, the Java 5 language features are as follows:
Autoboxing
for-each
enum
Varargs
Annotation
Static import
Generics
Let’s discuss the extent of the Groovy support for these features.
Groovy, because of its dynamic typing, supports autoboxing from the get-go. In fact, Groovy automatically treats primitives as objects where necessary. For instance, execute the following code:
| GroovyForJavaEyes/NotInt.groovy | |
| | int val = 5 |
| | |
| | println val.getClass().name |
The type is reported as follows:
| | java.lang.Integer |
In this code, we created an instance of java.lang.Integer ...
Read now
Unlock full access