加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

Integer简介

发布时间:2020-12-14 01:56:30 所属栏目:Linux 来源:网络整理
导读:// 当创建范围为[-128,127]时 Integer a = 1 ; Integer b = 1 ; Integer c = new Integer( 1 ); System. out .println( " a == b : " + (a == b)); System. out .println( " a == c : " + (a == c)); System. out .println(); // 当创建范围不为[-128,127]时
//      当创建范围为[-128,127]时
        Integer a = 1;
        Integer b = 1;
        Integer c = new Integer(1);
        System.out.println("a == b :" + (a == b));
        System.out.println("a == c :" + (a == c));
        System.out.println();
//      当创建范围不为[-128,127]时
        Integer d = 128;
        Integer e = 128;
        Integer f = new Integer(128);
        System.out.println("d == e :" + (d == e));
        System.out.println("d == f :" + (d == f));
        System.out.println("d e f 互不相等(false为正确测试结果):" + (d == e || d == f || e == f));
        System.out.println();
//      包装类均为值传递
        Integer g = 0;
        Integer h = new Integer(130);
        Test1(g);
        Test2(h);
        System.out.println("g = "+g);
        System.out.println("h = "+h);
    }
    static void Test1(Integer t) {
        t = 1;
        System.out.println("Test1内:  t = " + t);
    }
    static void Test2(Integer t) {
        t = 131;
        System.out.println("Test2内:  t = " + t);
    }
}

原文:https://blog.csdn.net/Cactus_Lrg/article/details/81489299 

测试结果如下:

a == b :true
a == c :false

d == e :false
d == f :false
d e f 互不相等(false为正确测试结果):false

Test1内: t = 1
Test2内: t = 131
g = 0
h = 130

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读