Integer是一个看着挺简单的,其实还是有点不一样,Integer是一个int的包装类,它是可以起到缓存作用的,在java基础里说过它的范围是(-128-127)在这个返回是有缓存的,不会创建新的Integer对象,并且可以设置它的最大值,通过设置VM参数。

下面先看一下源码:

 public static Integer valueOf(int i) {
if(i >= -128 && i <= IntegerCache.high)
return IntegerCache.cache[i + 128];
else
return new Integer(i);
}
private static class IntegerCache {
static final int high;
static final Integer cache[]; static {
final int low = -128; // high value may be configured by property
int h = 127;
if (integerCacheHighPropValue != null) {
// Use Long.decode here to avoid invoking methods that
// require Integer's autoboxing cache to be initialized
int i = Long.decode(integerCacheHighPropValue).intValue();
i = Math.max(i, 127);
// Maximum array size is Integer.MAX_VALUE
h = Math.min(i, Integer.MAX_VALUE - -low);
}
high = h; cache = new Integer[(high - low) + 1];
int j = low;
for(int k = 0; k < cache.length; k++)
cache[k] = new Integer(j++);
} private IntegerCache() {}
}
// value of java.lang.Integer.IntegerCache.high property (obtained during VM init)
private static String integerCacheHighPropValue;
static void getAndRemoveCacheProperties() {
if (!sun.misc.VM.isBooted()) {
Properties props = System.getProperties();
integerCacheHighPropValue =
(String)props.remove("java.lang.Integer.IntegerCache.high");
if (integerCacheHighPropValue != null)
System.setProperties(props); // remove from system props
}
}

通过设置VM的java.lang.Integer.IntegerCache.high可以调整它的最大值。虽然它是在一个静态代码块里是一个常量,但是是在初始化的时候赋值的,所以没什么影响。

演示修改JVM参数(eclipse):

package test1;

public class Demo1 {

    public static void main(String[] args) {
System.out.println(Integer.valueOf(200)==Integer.valueOf(200));
} }

输出结果:

false

怎么修改呢,看下面?

点击自己创建的项目,右键->Debug as ->Debug Configurations ->JavaApplication->点击自己的项目->Arguments->VM arguments设置->Apply->Debug

设置以后的结果:

最新文章

  1. 将.war文件解压到指定目录
  2. scjp考试准备 - 3 - 关于Arrays
  3. 众神看过来:IE11下鼠标中键(滚轮)导致的一个似乎无法解决的问题?!
  4. loadrunner http协议put模式脚本编写
  5. Java面向对象程序设计--接口和内部类
  6. MCS51浮点计算程序
  7. 4位或者5位led数码显示,485通信modbus,支持任意小数点写入,工业标准设置,可和plc,dcs,组态完美对接,支持定制修改
  8. Java开源博客My-Blog(SpringBoot+Docker)系列文章
  9. git对远程分支和tag的操作
  10. 配置完IDEA开发lua后用idea竟然打不开lua的文件。
  11. 美人鱼 hdu 5784
  12. RMAN 数据库克隆文件位置转换方法
  13. Could not find com.android.tools.build:aapt2:3.2.0-alpha14-4748712.
  14. VTK计算网格模型上的最短路径
  15. linux虚拟机设置本地yum源
  16. 8.2.1.3 Range 优化
  17. tcp网络通信的三次握手与三次挥手
  18. 推荐10款优秀的JavaScript Web UI库 框架和套件
  19. C# 源码计数器
  20. 第三方插件Vue-Lazyload

热门文章

  1. SpringMVC分页查询无法直接将对象转换成json的解决办法(报org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type:错)
  2. SpringMVC传递multiple类型select后台Controller的接收方法
  3. Hdu 5358 First One (尺取法+枚举)
  4. 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root
  5. 174 Dungeon Game 地下城游戏
  6. APP统计
  7. 转】[MySQL优化]为MySQL数据文件ibdata1瘦身
  8. 【Hibernate】多对多关系的表达
  9. 移动设备访问使用百度js跳转
  10. javascript中函数的四种调用模式详解