JavaEE 中DEBUG模式的设计
通过DEBUG模式我们可以快速的切换线上和线下的环境
public class Final {
private static boolean DEBUG;
static String HOST_NAME;
static int PASSWORD;
static {
disableDebug();
if (DEBUG) {
HOST_NAME = "admintest";
PASSWORD = 123456;
} else {
HOST_NAME = "admin";
PASSWORD = 20170720;
}
}
private static void enableDebug() {
DEBUG = true;
}
private static void disableDebug() {
DEBUG = false;
}
private Final(){}
}
public enum Const {
HOST_NAME(Final.HOST_NAME),
PASSWORD(Final.PASSWORD);
private Object value;
private Const(final Object value) {
this.value = value;
}
public Object getValue() {
return value;
}
public int getInt() {
return (int)value;
}
public String getString() {
return value.toString();
}
}
public class Use {
public static void main(String[] args) {
String s = Const.HOST_NAME.getString();
int i = Const.PASSWORD.getInt();
}
}