Is there a way to always execute a function before any other function of a class is called?
I have a class where I need to refresh some fields always before any func
You can have a protected getter method for data. Access getData method instead of using data field. Child classes will see only getData and will have updated data every time.
public class Example {
private int data;
public void function1(){
}
public void function2(){
}
protected int getData(){
refresh();
return data;
}
//@BeforeOtherFunction
private void refresh(){
// refresh data
}
}