首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Java中变化多端的常量

2012-10-24 
Java中变化无常的常量Java中变化无常的常量问题:第一版:直接编译UserConstantsTest,编译过程中会检测到Use

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






热点排行