先考两道题:

Integer a1 = 300;
Integer a2 =300;
System.out.print(a1 == a2); Integer b1 = 1;
Integer b2 = 1;
System.out.print(a1 == a2);

答案是:

false

true

Integer a1=1的时候,java编译器会默认编译成Integer a1=Integer.valueOf(1),valueOf方法里边会查看a1的值是否在-128到127,如果在这个范围,会从IntegerCache这个缓存中去取有没有值等于1的对象,如果有的话会返回缓存里的对象,没有的话会new一个。

马丹,那人说错了 integer 在-128 到127之间是静态初始化的 直接从缓存里面取得

JDK 1.7:

JDK 1.8: 

IntegerCache:

private static class IntegerCache {
static final int low = -128;
static final int high;
static final Integer cache[]; static {
// high value may be configured by property
int h = 127;
String integerCacheHighPropValue =
sun.misc.VM.getSavedProperty("java.lang.Integer.IntegerCache.high");
if (integerCacheHighPropValue != null) {
try {
int i = parseInt(integerCacheHighPropValue);
i = Math.max(i, 127);
// Maximum array size is Integer.MAX_VALUE
h = Math.min(i, Integer.MAX_VALUE - (-low) -1);
} catch( NumberFormatException nfe) {
// If the property cannot be parsed into an int, ignore it.
}
}
high = h; cache = new Integer[(high - low) + 1];
int j = low;
for(int k = 0; k < cache.length; k++)
cache[k] = new Integer(j++); // range [-128, 127] must be interned (JLS7 5.1.7)
assert IntegerCache.high >= 127;
} private IntegerCache() {}
}

自动装箱的缓存??

Long 也是:

##Double,Float 不一样:

Double: 

Float: 

String??

http://blog.csdn.net/u011240877/article/details/47721135

最新文章

  1. [译] MongoDB Java异步驱动快速指南
  2. C# WebClient 使用http免费代理。
  3. JAVA中JDBC连接数据库
  4. reverse(), extend(), sort() methods of list
  5. 团队自动化环境搭建与管理--php博弈
  6. php上传常见文件类型对应的$_FILES[&quot;file&quot;][&quot;type&quot;](转)
  7. Java Instanceof
  8. android工具类常用方法
  9. hadoop性能测试命令
  10. 如何一步一步用DDD设计一个电商网站(十二)—— 提交并生成订单
  11. memcached优化方案实例
  12. 常用DOS命令之通俗易懂篇
  13. Log4j 2X 日志文件路径问题
  14. ext2文件系统学习(一)
  15. MySQL Network--Localhost与127.0.0.1的差异
  16. 数据分析——Matplotlib图形绘制
  17. CF815C Karen and Supermarket
  18. springcloud(十):服务网关zuul初级篇
  19. PHP中对象的传值方式
  20. c语言实现CRC校验和

热门文章

  1. 【千纸诗书】—— PHP/MySQL二手书网站后台开发之功能实现
  2. [Parcel] Running TypeScript with parcel-bundler
  3. WCF调试异常信息:ServiceHost 仅支持类服务类型
  4. webpack的配置文件entry与output
  5. js map、filter、forEach
  6. Cookie小案例-----记住浏览过的商品记录
  7. spring事务管理源码解析--加了@Transactional注解后Spring究竟为我们做了哪些事情?
  8. windows操作系统记事本保存操作时间、字符映射表的打开、步骤记录器使用
  9. ZooKeeper_基础知识学习
  10. C++程序设计(第4版)读书笔记_C++概览:基础知识