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类型
             */
        }
    }
  • 相关阅读:
    shell编程介绍
    第一章作业
    jenkins介绍与操作
    gitlab介绍与操作
    github介绍与操作
    git介绍与操作
    zabbix监控tomcat与安全规范
    js-20170605-基本语法
    webstorm激活方法
    mac的一些基本设置(分享篇)
  • 原文地址:https://www.cnblogs.com/lxh520/p/8196843.html
Copyright © 2011-2022 走看看