IntegerCache


/**
 * 本类是JDK源码中的示例,思维很巧
 * @author TANGHAI
 *
 */
class IntegerCache {
	private IntegerCache() {
	}

	static final Integer cache[] = new Integer[-(-128) + 127 + 1];

	static {
		for (int i = 0; i < cache.length; i++)
			cache[i] = new Integer(i - 128);
	}
	
	public static void main(String[] args) {
		System.out.println(cache.length);
		for (Integer i : cache) {
			System.out.println(i);
		}
		
	}
}

 

你可能感兴趣的:(jdk,cache,String,Integer)