Groovy web console

subscribe to the feed Subscribe
to this
site

Gstring and {}

Published 2 months ago by Bhagwat
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
class Person{
    String name 
    String toString() {"Person{name = $name}"}
}

List<Person> persons = [ new Person(name: 'Person 1'), new Person(name: 'Person 2') ]
assert  ['Person 1', 'Person 2'] == persons.name

println "${persons.first()} got."

Person person = persons.first()

println "$person.name will work"
println "${person.name} will work as well"
println "${person.name.toUpperCase()} will work as well"
//Below fails with groovy.lang.MissingPropertyException: Exception evaluating property 'first'
//println "$persons.first() got."
//println "$person.name.toUpperCase() will not work"