I would suggest the Singleton template (I know that many people don't like it), but it seems like this is the easiest solution. Take a look at this piece of code:
public enum Constants {
INSTANCE;
public void isInDebugMode() {
return true;
}
}
Here's how you use it (even from static code):
if(Constants.INSTANCE.isInDebugMode()) {....}
You might also think of a more complex solution:
public enum Constants {
DEBUG(true),
PRINT_VARS(false);
private boolean enabled;
private Constants(boolean enabled) {
this.enabled = enabled;
}
public boolean isEnabled() {
return enabled;
}
}
Usage example:
if(Constants.DEBUG.isEnabled()) {....}
source
share