Java Magazine, Mar/Apr 2018
ORACLE COM JAVAMAGAZINE MARCH APRIL 2018 71 jvm languages Miscellaneous Features Groovy 3 includes a wide range of smaller changes that are interesting Some are trivial extensions used to make it more Java friendly including A do while loop Java style for loops with multiple looping variables Java style array initialization Javas try with resources syntax Each of these could be done more idiomatically with Groovy alternatives but its convenient to be able to use the Java versions if youre still learning Some of the new additions are simple For example you can use an exclamation point on the in and instanceof operators to test for negation assert 45 instanceof Date assert 4 in 1 3 5 7 The Elvis operator has been in Groovy for a long time It is a minimal form of Javas ternary operator which uses a supplied value if its true according to the Groovy truth or a default if not The new Elvis assignment operator lets you check for the Groovy truth and use the result in an assignment all in a single statement @ groovy transform Canonical class User String name User u new User u name u name default Elvis operator u name default Elvis assignment assert u toString User default
You must have JavaScript enabled to view digital editions.