Java--常用类--包装类

  1.  

  2.  

     

  3.    

  4. package com.model.wrapper;
    
    /**
     * @Description:测试类
     * @Author: 张紫韩
     * @Crete 2021/7/3 22:31
     * 演示把中常见的包装类
     */
    public class WrapperDemo01 {
        public static void main(String[] args) {
            //三元运算符是一个整体,Object转化的时候会转换成一个大的精度的类型即Double,所以1 转型为1.0
            Object obj=true?new Integer(1):new Double(2.0);
            System.out.println(obj.toString());
    /*
    *    public static Integer valueOf(int i) {
            if (i >= IntegerCache.low && i <= IntegerCache.high)
            * //传进来的数值在-128到127就直接返回数组里面的数值(预先定义好的Integer对象,数值从-128到127),如果数组里面有,就直接用
            * 就不用new了,所有返回的对象是一样的
                return IntegerCache.cache[i + (-IntegerCache.low)];
            return new Integer(i); //如果传进来的范围不在-128到127 就new一个对象返回
        }
    * */
            Integer i=1;
            Integer j=1;
            System.out.println(j==i);
    
            int a=1;
            int b=1;
            System.out.println(a==b);
    //
            int x=100;
            Integer y=100;
            System.out.println(x==y); //只要有基本数据类型,比较的就是值是否相等,并非对象相等(值+地址)
        }
    }

     

     

posted @ 2021-07-03 23:46  张紫韩  阅读(47)  评论(0编辑  收藏  举报