al.add(n);//不可以
这个在JDK5之前应该是不可以的,JDK5之后是可以的。
JDK5的一个新特性,自动装箱与拆箱,可在需要的时候自动将Integer转换为int,或才将int转换为Integer作者: 胡团乐 时间: 2012-6-4 12:04
int 是基本类型 Integer是它的封装类还有
byte Byte
short Short
char Character
float Float
double Double
long Long 这是1.5出现的新特性
对于int 和 Integer 的自动装箱问题 看个代码示例:
public class AutoBox {