public static void main(String[] args) throws Exception {
Class cache = Integer.class.getDeclaredClasses()[0];
Field c = cache.getDeclaredField("cache");
c.setAccessible(true);
//获取-128到127的数组
Integer[] array = (Integer[]) c.get(cache);
// 将数据下标位置129值为1,赋值给下标130值为1
array[130] = array[129];
// 将数据下标位置129值为1,赋值给下标131值为1
array[131] = array[129];
Integer a = 1;
//会将1装箱成数组array[129],会将2装箱成数组array[130],会将3装箱成数组array[131]
if (a == (Integer) 1 && a == (Integer) 2 && a == (Integer) 3) {
System.out.println("true");
}
//这是数值的比较会将a拆箱为int类型1进行比较
if (a == 1 && a == 2 && a == 3) {
System.out.println("false");
}
}
Is a==1&&a==2&&a==3 true or false?
Guess you like
Origin blog.csdn.net/qq_19891197/article/details/131606862
Recommended
Ranking