读书人

Java中变化多端的常量

发布时间: 2012-10-24 14:15:58 作者: rapoo

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");


参考:
Inconstant Constants in Java:http://www.javaworld.com/community/node/3400






读书人网 >编程

热点推荐