Tutorial by Examples

Groovy's safe navigation operator allows to avoid NullPointerExceptions when accessing to methods or attributes on variables that may assume null values. It is equivalent to nullable_var == null ? null : nullable_var.myMethod() def lst = ['foo', 'bar', 'baz'] def f_value = lst.find { it.startsWi...
class User { String name int age } def users = [ new User(name: "Bob", age: 20), new User(name: "Tom", age: 50), new User(name: "Bill", age: 45) ] def null_value = users.find { it.age > 100 } // no over-100 found. Null null_value?.name?....

Page 1 of 1