import java.util.*;
import java.lang.*;
import java.io.*;
import java.lang.reflect.*;
 
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		doTricky1();
		doTricky2();
		System.out.printf(" 128 + 1 = %d\n",128+1);
	}
	
	private static void doTricky1(){
		try{
			Class iCache=Integer.class.getDeclaredClasses()[0];
			Field f = iCache.getDeclaredField("cache");
			int low=-128;// low 保持不動
			int high=1000;//把 cache 從 -128~127 改為 -128~1000
			
			Integer[] cacheArray=new Integer[high-low];
			for(int k = 0 , j=low ; k < cacheArray.length; k++)
				cacheArray[k] = new Integer(j++);
			setFinalStaticValue(f,cacheArray);
			 
			f = iCache.getDeclaredField("high");
			setFinalStaticValue(f,high);
		 
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	private static void doTricky2(){
		try{
			Class iCache=Integer.class.getDeclaredClasses()[0];
			Field f = iCache.getDeclaredField("cache");
			f.setAccessible(true);
			Integer[] cacheArray=(Integer[])f.get(iCache);
			cacheArray[257]=5; // 128 + 129 = 257
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	private static void setFinalStaticValue(Field fd,Object val){
		try{
			fd.setAccessible(true);
			Field mdfField = Field.class.getDeclaredField("modifiers");
			mdfField.setAccessible(true);
			//重點是這裡，把 final 屬性拿掉
			mdfField.setInt(fd, fd.getModifiers() & ~Modifier.FINAL);
			fd.set(null, val);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}