博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Integer.valueOf(int i)源码
阅读量:6941 次
发布时间:2019-06-27

本文共 1313 字,大约阅读时间需要 4 分钟。

  hot3.png

Integer.valueOf(int i)源码中 assert

/**     * Returns an {@code Integer} instance representing the specified     * {@code int} value.  If a new {@code Integer} instance is not     * required, this method should generally be used in preference to     * the constructor {@link #Integer(int)}, as this method is likely     * to yield significantly better space and time performance by     * caching frequently requested values.     *     * This method will always cache values in the range -128 to 127,     * inclusive, and may cache other values outside of this range.     *     * @param  i an {@code int} value.     * @return an {@code Integer} instance representing {@code i}.     * @since  1.5     */    public static Integer valueOf(int i) {        assert IntegerCache.high >= 127;        if (i >= IntegerCache.low && i <= IntegerCache.high)            return IntegerCache.cache[i + (-IntegerCache.low)];        return new Integer(i);    }

assert的作用是计算表达式expression,

jdk1.7中存在,1.8中源码中已删除该代码。(频繁的调用会极大的影响程序的性能,增加额外的开销)

注意:有些地方,assert不能代替过滤条件

Other:

Integer.valueOf(int i)的范围

public static void main(String[] args) {    Integer a = 1;    Integer b = 1;    Integer c = 128;    Integer d = 128;    System.out.println(a==b);    System.out.println(c==d);}

代码执行结果:

truefalse

 

转载于:https://my.oschina.net/miwang/blog/1605507

你可能感兴趣的文章
利用ResultFilter实现asp.net mvc3 页面静态化
查看>>
PHP 图片加水印的方法
查看>>
javascript报错集锦
查看>>
koa2实现拦截器进行登录前session校验
查看>>
[java]窗口中的菜单项
查看>>
[ACM] hdu 2191 珍惜现在,感恩生活 (多重背包)
查看>>
python-并发编程之多进程
查看>>
JavaScript严格模式详解
查看>>
小X的佛光 NOIP模拟赛 倍增LCA 树结构
查看>>
The Himalayas (zoj 3809)
查看>>
[模板] 网络流相关/最大流ISAP/费用流zkw
查看>>
SCAU 10692 XYM-入门之道
查看>>
使用Ajax内容签名,减少流量浪费
查看>>
mysql 架构 ~异地容灾
查看>>
mui 上拉刷新加载template数据
查看>>
JavaScript中==比较时的过程
查看>>
HIDKomponente使用读写Hid设备一瞥
查看>>
gruntjs本地安装的流程
查看>>
mysql_real_escape_string
查看>>
elasticsearch配合mysql实现全文搜索
查看>>