package cc.openhome;
public class IntegerDemo2 {
public static void main(String[] args) {
Integer data1=10;
Integer data2=8;
System.out.println(data1.doubleValue()/3);
System.out.println(data1.compareTo(data2));
int i=10;
Integer wrapper1=i;
System.out.println(wrapper1);
也可使用一般化的number类装箱
Number number=3.14f;
System.out.println(number);
wea会参考至Integer,若被指定为int 型的变量foo1,则会自动取得打包的int型再指定给foo1
Integer wea=10;
int foo1=wea;
System.out.println(foo1);
在运算时候也可以自动拆箱和装箱
Integer j=10;
System.out.println(j+10);
System.out.println(j++);
foo会参考至Boolean实例,在进行&&运算时候,会将foo拆箱,再与false进行&&运算
Boolean foo=true;
System.out.println(foo &&false);
}
}
结果: