Java中变化无常的常量
Java中变化无常的常量
问题:
第一版:
直接编译UserConstantsTest,编译过程中会检测到UserConstants尚未编译,然后会编译UserConstants
运行结果如图所示:
第二版:
只修改UserConstants,并且只重新编译UserConstants,得到结果如下图所示:
原因:
private static String ident(final String constant) { return constant; } public static final String USER_NAME = ident("root"); public static final String PASSWORD = ident("123456789"); public static final String DESCRIPTION = ident("This is root account");