有感于这个帖子:/t/472515
来一个鬼畜版,先猜一猜程序输出结果,然后跑一把验证下看看:
public static void main(String[] args) {
try
{
fuck();
}
catch (NoSuchFieldException e)
{
e.printStackTrace();
}
catch (IllegalAccessException e)
{
e.printStackTrace();
}
for (Integer i = 1; i < 4; i++) {
System.out.println(i);
}
}
private static void fuck() throws NoSuchFieldException, IllegalAccessException {
Integer x = 100;
Class c = Integer.class.getDeclaredClasses()[0];
Field f = c.getDeclaredField("cache");
f.setAccessible(true);
Integer[] cache = (Integer[]) f.get(x);
cache[130] = cache[131];
}
来一个鬼畜版,先猜一猜程序输出结果,然后跑一把验证下看看:
public static void main(String[] args) {
try
{
fuck();
}
catch (NoSuchFieldException e)
{
e.printStackTrace();
}
catch (IllegalAccessException e)
{
e.printStackTrace();
}
for (Integer i = 1; i < 4; i++) {
System.out.println(i);
}
}
private static void fuck() throws NoSuchFieldException, IllegalAccessException {
Integer x = 100;
Class c = Integer.class.getDeclaredClasses()[0];
Field f = c.getDeclaredField("cache");
f.setAccessible(true);
Integer[] cache = (Integer[]) f.get(x);
cache[130] = cache[131];
}