zoukankan      html  css  js  c++  java
  • 5-4 对象包装器和自动装箱

    import java.util.ArrayList;
    public class BaoZhang {
    
        /**
         * @author:lixh
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
    
            method1();
        }
        
        public static void method1(){
            /**
             * 1.对象包装器    final修饰
             * Byte, Integer,Short,Float,Long,Double,Character,Boolean
             * 前6种继承Number类型
             * 
             */
            
            /**
             *2. 自动装箱,拆箱
             */
            ArrayList<Integer> list  = new ArrayList<Integer>();
            list.add(1);//自动装箱
            int y = list.get(0);//自动拆箱
            
            //编译器会自动拆箱,然后自增,再自动装箱
            Integer x = 1;
            x++;
            /**
             * 3.自动装箱规范
             * 要求Byte,Short,Boolean<127
             * short,int数值介于 -128---127被包装到固定的对象
             */
            
            Integer a = 100;
            Integer b = 100;
            Integer c = 1000;
            Integer d = 1000;
            System.out.println(a==b);
            System.out.println(c==d);
            
            Byte m = 20;
            Byte n = 20;
            Byte w = 127;
            Byte z = 127;
            System.out.println(m==n);
            System.out.println(w==z);
            
            /**
             * 4.包装器类不能实现修改值参数的方法,因为是final修饰
             * 除非用Holder类型
             */
        }
    }
  • 相关阅读:
    3.24课堂
    3.23作业
    3.23课堂
    3.20作业
    3.20课堂
    3.19作业
    3.19课堂
    3.18课堂
    3.18作业
    46、表与表的连接
  • 原文地址:https://www.cnblogs.com/lxh520/p/8196843.html
Copyright © 2011-2022 走看看