Contents

Groovy 3 Release Note Hightlights

I’m a huge Fan of groovy and therefore always excited about new additions and changes to the groovy lang. Therefore, here’s a list of my personal highlights of the groovy 3 release.

The complete release-notes can be found here: Groovy 3 Release Notes:

!in Operator

4 !in [5, 6, 19] // true

!instanceof Operator

LocalDate.now() !instanceof Temporal // false
LocalDate.now() !instanceof Instant // true

?= Elvis Operator

def last = null
last ?= 'Doe'
last == 'Doe'

=== and !== Identical Operators

def emp1 = new Employee(name: "Simon Jakubowski")
def emp2 = new Employee(name: "Simon Jakubowski")
def emp3 = emp1

emp1 == emp2 // true
emp1 === emp2 // false
emp1 === emp3 // true

safe map, list, array access

def emps = [
  "boss"     : ["joe"],
  "developer": ["sja", "sro", "tti"]
]

emps["boss"] // ["joe"]
employees["boss"] // throws NPE
employees?["boss"] // null

Support for lambda expressions + Method References

["test", "arba"]
  .stream()
  .map(String::toUpperCase)
  .collect(Collectors.toList())

Reduction of the main groovy package

org.codehaus.groovy:groovy:3.0.8
org.codehaus.groovy:groovy-json:3.0.8
* groovy.json.JsonSlurper
org.codehaus.groovy:groovy-xml:3.0.8
* groovy.xml.XmlSlurper