引用final static 的常量编译后存储常量而不是引用
//One.java
public class One {
public final static String str ="aaaaaaa";
}
//Two.java
public class Two {
String bb = One.str;
}
编译后:
//One.class
public class One
{
public final static String str = "aaaaaaa";
}
//Two.class
public class Two
{
String bb = "aaaaaaa";
}
如果修改 One.java 后编译One.java ,Two.java存储的还是旧值,所以需要都编译
网友评论