One option would be:
def result = obj.hasProperty( 'b' ) ? obj.b : null
Which would return null if the object doesn't have the property...
Another would be to add propertyMissing
to your class like so:
def propertyMissing( name ) {
null
}
This means that any missing properties would just result in null.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…