Never been to DZone Snippets before?

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

About this user

David R. MacIver http://unenterprise.blogspot.com

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

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); } } }); 
    }


}

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS