I have several variables that are global and mainly do not change.
Sometimes (every few month) I though want to change them.
They are saved in the DB.
Problem is: if I change the static vars, other services still use the old values.
What am I doing wrong?
class Config {
public static Default DEFAULTS = new Default();
//several other static defaults
public static in DIGIT = DEFAULTS.getDigit();
}
class Default() {
private int digit = 0;
//get+set
}
class Service() {
updateDefaults() {
Config.DEFAULTS.setDigit(2);
dao.update(Config.DEFAULTS);
}
}
Problem: other services that use Config.DIGIT; still use the old default value of digit = 0.
The issue is that you are updating the value of digits in the DEFAULTS instance of Default. However the value for Config.DIGITS is already set and not reset, i.e. the assignment of DIGITS does not get updated because you change the value of DEFAULTS.digit.
Additionally, I assume there are some typos in this code, as Config.DEFAULTS is private here can not be updated directly.