java误用反射会带来的一个小问题,2+2=5!

public class TestInteger {code

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

}get

相关文章
相关标签/搜索