DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
2 + 2 = 5
Here is some very exciting Java code for printing 5.
import java.security.*;
import java.lang.reflect.*;
import java.util.*;
public class Test
{
public static void main(String[] args) throws Exception
{
AccessController.doPrivileged( new PrivilegedAction<Object>(){ public Object run(){try {
Field field = Class.forName("java.lang.Integer$IntegerCache").getDeclaredFields()[0];
field.setAccessible(true);
Integer[] cache = (Integer[])field.get(null);
cache[130] = 3;
Integer foo = 2;
System.out.println(foo + 2);
return null;} catch(Exception e) { throw new RuntimeException(e); } } });
}
}





Comments
Snippets Manager replied on Wed, 2007/02/14 - 2:44pm
Snippets Manager replied on Mon, 2012/05/07 - 2:36pm
Greg Miller replied on Mon, 2006/10/02 - 8:25pm