Hi All,
I was wondering if it is possible, using reflection, or something similar to invoke a method whenever a variable is accessed in read or write mode. In a nutshell my goal is similar to the behavior of C# properties.
Example: Let's say I have a two classes A and B...
public class A{
public int field;
public void foo(){ System.out.println("Field modified");}
}
public class B{
public void bar(A a){
a.field = 1;
}
}
...and I want to execute the method A.foo() whenever a.field is written.
Is this achieveable in Java?
Thanks in advance
p.s. I'm aware that good programming practices suggest to use getter and setter. I just need to know if what I want to do is feasible.
ac