annotations - Java: run custom code on field access -
my use-case following: have class member field, accessed of methods. able run custom code modifying member field each time accessed methods see modified value. initial idea use custom annotation.
so wanted have this:
class myclass { ... @myannotation myfieldtype myfield; ... public void mymethod() { ... smth = myfield.getsomething(); ... } }
such when run method mymethod() (or other class method), code executed before modifying myfield:
void myannotationprocessor() { ... myfield.change(); }
so when access myfield in mymethod, see changed myfield , not 1 before method call. basically, in aspect, @myannotation should @before in junit.
i tried implement @myannotation custom constraint, but, unfortunately, did not work planned, constraint validator never called when methods accessed field.
is there way annotations? or fighting lost struggle?
any appreciated.
update
i have solved problem in entirely different way, without having intercept field access. big commented.
Comments
Post a Comment