这是这段代码:
int[] someArray = {0, 1, 2, 3};
//System.out.println(someArray[0].toString()); int cannot be dereferenced
// creating Object element with use of primitive element fails
//Object newObject = new Object(someArray[0]); constructor Object in class java.lang.Object cannot be applied to given types;
for(Object someObject : someArray)
{
// here int is casted to Object
System.out.println(someObject.toString()); // prints 0, 1, 2, 3
}
原始类型变量(数组的元素)不能显式转换为 Object 是如何发生的,但是在 for 循环中,这个原始元素以某种方式转换为 Object?