现在的位置: 首页 > 综合 > 正文

IntegerCache

2013年08月06日 ⁄ 综合 ⁄ 共 311字 ⁄ 字号 评论关闭

/**
 * 本类是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);
		}
		
	}
}

 

抱歉!评论已关闭.