Groovy web console

subscribe to the feed Subscribe
to this
site

map default values

Published 4 months ago by asd with tags map key
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
class Advis {
    String name = "default class value"
    int age
}

def map = [name: null, age: 42]
//def map = [name: "set", age: 42]


map.name = map.containsKey("name") ? map.name : "default map value"
//map.name = map.name ?: "default map value"


Advis advis = new Advis(map)


advis.name == null
//advis.name == "set"
//advis.name == "default map value"
//advis.name == "default class value"