@
dingwen07 #34 谢谢您提供的文档,而正如文档里所说:
This ensures that in most common cases, the behavior will be the desired one, without imposing an undue performance penalty, especially on small devices. Less memory-limited implementations might, for example, cache all char and short values, as well as int and long values in the range of -32K to +32K.
按我的理解,这只是 JVM 做的一个底层性能优化,而且它本身也不保证一切情况下不变,比如在内存充裕的设备,缓存池范围可能就是 -32k to 32k 了。
那么,纠结 Integer 的 100 == 100 返回啥,200 == 200 返回啥的现实意义是啥?除非说因为这个会很容易造成某方面的 bug,需要额外注意。不然这就是背面试题的事?