2.6.2021 |

Groovy 3 Highlights

Mit Gradle 7 kam auch die neue Spock Version 2.0 welche groovy 3.x beinhaltet.

Hier eine Liste einiger "Highlights" der 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
Simon Jakubowski
Zur Übersicht

Mehr vom DevSquad...

Sven Röttering

Lazy Loading in Angular

Simon Jakubowski

HowTo Query Optimization