运行时常量池的一些理解
public class TestCl{
static final Integer ii = 1000;
private final Integer b = 1000;
public static void main(String[] args) {
TestCl cl = new TestCl();
System.out.println(cl.b == TestCl.ii);
}
}
输出false
public class TestCl{
static Integer ii = 1000;
private Integer b = 1000;
public static void main(String[] args) {
TestCl cl = new TestCl();
System.out.println(cl.b == TestCl.ii);
}
}
输出false
比较一二说明final关键字修饰的常量只是不许修改, 不代表把其对象内容放入运行时常量池中
public class TestCl{
static Integer ii = 1;
private Integer b = 1;
public static void main(String[] args) {
TestCl cl = new TestCl();
System.out.println(cl.b == TestCl.ii);
}
}
public class TestCl{
public static void main(String[] args) {
final TestCl cl = new TestCl();
final TestCl c2 = new TestCl();
System.out.println(cl == c2);
}
}
同理输出false