I have following two domain classes in Grails 1.1.2:
class A implements Serializable {
MyEnumType myField
Date fieldChanged
void setMyField(MyEnumType val) {
if (myField != null && myField != val) {
myField = val
fieldChanged = new Date()
}
}
}
class B extends A {
List children
void setMyField(MyEnumType val) {
if (myField != null && myField != val) {
myField = val
fieldChanged = new Date()
children.each { child 开发者_C百科-> child.myField = val }
}
}
When I set B instance's myField, I get the setter into the cycle... myField = val line calls setter again instead of assiging the new value.
Any hint how to override the setter correctly? Thanks
Use the this
keyword to avoid calling the getter or setter:
this.myField = val
See http://groovy.codehaus.org/Groovy+Beans#GroovyBeans-Propertyandfieldrules
精彩评论