单纯的记录一下Java反射的“乱伦”

154 阅读1分钟
public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
    Class cache = Integer.class.getDeclaredClasses()[0];
    Field myCache = cache.getDeclaredField("cache");
    myCache.setAccessible(true);
    Integer[] newCache = (Integer[]) myCache.get(cache);
    newCache[132] = newCache[134];
    int a = 2;
    int b = a + a;
    System.out.printf("%d + %d = %d", a, a, b);
}