For parameterless methods, Groovy needs parenthesis. I can think of two solutions:
Solution 1: Metaclass the getter getFullName
:
Dynamo dynamo = [ firstName: 'bob', lastName: 'dobbs' ]
dynamo.metaClass.getFullName = { "$lastName, $firstName" }
assert dynamo.fullName == 'dobbs, bob'
Solution 2: Hook into the property getters with getProperty
:
Dynamo dyn2 = [ firstName: 'john', lastName: 'doe' ]
dyn2.metaClass.getProperty = { String property ->
if (property == "fullName") {
"${delegate.lastName}, ${delegate.firstName}"
}
}
assert dyn2.fullName == 'doe, john'