/**
* @description: 通过利用Integer的缓存机制,修改缓存的值,将缓存2和3的位置都修改为1,实现1 == 2 == 3
* @author: chengchangxin
* @date: 2024/6/4 上午10:15
**/
private static void test7() throws NoSuchFieldException, IllegalAccessException {
Class cache = Integer.class.getDeclaredClasses()[0];
Field c = cache.getDeclaredField("cache");
c.setAccessible(true);
//取出缓存数组
Integer[] array = (Integer[]) c.get(cache);
// array[129] is 1
array[130] = array[129];
// Set 2 to be 1
array[131] = array[129];
// Set 3 to be 1
Integer a = 1;
if(a == (Integer)1 && a == (Integer)2 && a == (Integer)3){
System.out.println("实现1 == 2 == 3");
}
}
标签:缓存,java,实现,cache,&&,129,Integer,array
From: https://www.cnblogs.com/ccx-lly/p/18235154