class Person {
String name
String toString() { name }
}
def John = new Person(name:'John')
def Ram = new Person(name:'Ram')
def p = John
def gs = "Name: ${p}"
assert gs == 'Name: John'
p = Ram
assert gs == 'Name: John'
john.name = 'Ram'
assert gs == 'Name: Ram'
You defined John with a capital J
But you try to set john.name with a lowercase j
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.