Groovy web console

subscribe to the feed Subscribe
to this

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'] ==

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

Person person = persons.first()

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