包装类(处理8种基本数据类型)

 1 public class DemoClass4DataType {
 2     public static void main(String[] args) {
 3         //TODO 包装类这里主要处理8种【基本】数据类型,
 4         // 相对应的【引用】数据类型是继承了Object的,所以引用类型可以使用Object属性和方法
 5         // 但基本类型没有,所以java专门给8种【基本】类型配置了对应的类,来操作基本类型数据
 6         /*
 7         * 8种基本类型:
 8         * byte short int long 数字
 9         * float double 浮点
10         * char 字符
11         * boolean bool类型
12         * */
13         //包装类
14         Byte b = null;
15         Short s = null;
16         Integer i = null;
17         Long l = null;
18         Float f = null;
19         Double d = null;
20         Character c = null;
21 
22         //拿interger做例子
23         int i1 = 10;
24         //TODO 自动装箱
25         Integer it = new Integer(i1);
26         Integer it2 = Integer.valueOf(i1);
27         Integer it3 = i1;  //Integer.valueOf()的简化写法
28 
29         //自动拆箱
30         int i2 = it3.intValue();
31         int i3 = it3; //intValue() 的简化写法
32     }
33 }

 

posted @ 2025-10-15 13:43  字节虫  阅读(14)  评论(0)    收藏  举报