我们说Java不是纯粹的面向对象编程,因为原始数据类型不是对象。但在下面的代码中,对象如何持有基本数据类型?
public class Test{
public Object meth(Object obj){
System.out.println(obj instanceof Object);//It prints true
System.out.println("Value = "+obj);//It prints "Value = 1"
return obj;
}
public static void main(String[] args) {
int a = 1;
System.out.println(new Test().meth(a));
}
}
autoboxing
的文档:http://docs.oracle.com/javase/1.5.0/docs/guide/language/autoboxing.html - ZhangChn