Is there a way for the Chameleon class to ever see that it has a
"lastColor" property?
class Chameleon{
String color = "green"
void printAllMyProperties(){
this.properties.each{println it}
}
}
trait ColorChanging {
String lastColor
def changeColor = {newcolor ->
lastColor = this.color
this.color = newcolor
}
}
def mylizard = new Chameleon().withTraits(ColorChanging)
mylizard.changeColor(blue)
mylizard.printAllMyProperties()
mylizard.properties.each{println it}
The outputs of the two above lines don't match. lastColor isn't available
from inside the class.
This seems like it should be possible, but I tried several things including
the declaredFields property and could not get the desired effect.
In this script, I'm looking for a way for my instance to reference all the
properties it's received from the trait. I guess it's same situation with
inheritance, and properties added by propertymissing.
Gerald R. Wiltse
[email protected]