日期:2014-05-20 浏览次数:21813 次
public class LongDemo {
public static void main(String[] args) {
Long a = 10L;
Long b = 12L;
Long c = a + b;
/*
下面这句编译会报错(Incompatible conditional operand types long and Long),
也就是说编译器认为(a + b)不是Long类型的,而是long类型的。
因为自动拆箱了。
*/
System.out.println((a + b) instanceof Long);
//下面这句就可以,因为上面用Long去接收a + b的值了,就又装箱了。
System.out.println(c instanceof Long);
}
}