我在 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 -> child.myField = val }
}
}
当我设置 B 实例的 myField 时,我让 setter 进入循环...... myField = val 行再次调用 setter 而不是分配新值。
任何提示如何正确覆盖设置器?谢谢