Reputation: 185
suppose I have MyClass domain class:
class MyClass {
String prop1
String prop2
String prop3
}
I wonder is there any way to delete for example prop1 property from MyClass object ?
Upvotes: 2
Views: 2491
Reputation: 187499
The only way to actually delete the property is to remove it from the source file. However, you can make attempts to access the property exhibit the same behaviour as an attempt to access a non-existent property.
class MyClass {
String prop1
String prop2
String prop3
}
MyClass.metaClass {
// Intercept attempts to get the property
getProp1 = {-> throw new MissingPropertyException("can't get prop1")}
// Intercept attempts to set the property
setProp1 = {throw new MissingPropertyException("can't set prop1")}
}
Upvotes: 5