Java基础(basis)-----包装类详解

1. 包装类的概念

    Java的基本数据类型不是对象,无法参与转型,泛型,反射等过程,由此提供了包装类

  •     boolean包装类Boolean
  •     byte包装类Byte
  •     short包装类Short
  •     int包装类Integer
  •     long包装类Long
  •     char包装类Character
  •     float包装类Float
  •     double包装类Double

2. 装箱和拆箱

  •      装箱就是自动将基本数据类型转换为包装器类型
  •      拆箱就是自动将包装器类型转换为基本数据类型
package com.practice;

public class Practice {
    public static void main(String[] args) {
        int m=3;
        Integer integer=m; //自动装箱
        int n=integer; //自动拆箱
        System.out.println(integer);
        System.out.println(n);
    }
}

猜你喜欢

转载自www.cnblogs.com/fengfuwanliu/p/11403795.html