CodeEggDailyInterview
CodeEggDailyInterview copied to clipboard
有了基本数据类型,为什么还需要包装类型?
基本数据类型,java中提供了8中基本的数据类型。boolean int float等
包装类型:每一个基本的数据类型都会一一对应一个包装类型。
boolean —–>Boolean
Int ——–>Integer
装箱和拆箱
装箱:把基本的数据类型转换成对应的包装类型.
Integer .valueOf(1)
Integer i = 1;自动装箱,实际上在编译时会调用Integer .valueOf方法来装箱
拆箱:就是把包装类型转换为基本数据类型.基本数据类型 名称 = 对应的包装类型。
Integer i = 1;
int j = i;//自动拆箱//int j = i=intValue();手动拆箱
自动拆箱:实际上会在编译调用intValue
Java是一个面向对象的语言,而基本的数据类型,不具备面向对象的特性。
null Integer—>null int—->0 用Integer和int分别表示Person这个类的ID
Max 最大值
min 最小值
缓存值:对象缓存,Integer i=1; integer j= 1;i ==j