扩展java Integer缓存 [英] Extending java Integer cache
本文介绍了扩展java Integer缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一般建议使用 Integer.valueOf(int)
而不是 new Integer(int)
因为缓存。
There's a general advice to use Integer.valueOf(int)
instead of new Integer(int)
because of caching.
在JDK 5+中,您应该使用 valueOf
因为整数
现在缓存整数
-128
和 127
并且可以每次都返回相同的 Integer(0)
对象,而不是在全新的相同 Integer $上浪费对象构造c $ c>对象。
In JDK 5+, you should really use valueOf
because Integer
now caches Integer
objects between -128
and 127
and can hand you back the same exact Integer(0)
object every time instead of wasting an object construction on a brand new identical Integer
object.
如何扩展范围?
推荐答案
你可以使用java.lang.Integer.IntegerCache.high属性增加此缓存的大小。
ex:
You can use the java.lang.Integer.IntegerCache.high property to increase the size of this cache.
ex :
java -Djava.lang.Integer.IntegerCache.high=4096 SomeClass.class
这篇关于扩展java Integer缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文