JAVA基础(三)·自动装箱和拆箱

来源:互联网 发布:阿里云企业备案表 编辑:程序博客网 时间:2024/05/15 22:38
public class TestAutoBoxing{        public static void main(String[] args)         Integer t1 = new Integer(127);    Integer t2 = new Integer(127);    System.out.println("t1==t2:"+(t1==t2));    Integer t3 = 127;    Integer  t4 = 127;    System.out.println("t3==t4:"+(t3==t4));    System.out.println("t1==t4:"+(t1==t4));    Integer t5 = 128;    Integer t6 = 128;    System.out.println("t5==t6:"+(t5==t6));        //运行结果    //false,true,false,false   /* 适用范围:        boolean类型的值            所有byte类型的值            在-128~127之间的short类型的值            在 -128~127之间的int类型的值            所有所有在\u00000~\u007F之间的char类型的值           注:当int类型的数据在-128~127的时候,通过自动装箱产生的Integer对象会缓存在内存中的,而试图通过  自动装箱的方式产生另一个相等值得Integer对象的时候,系统将不会重新生成新的对象而是直接使用 内存中已经存在的Integer对象      */                        }



0 0