If there is a method call MyClass.returnArray()
and I iterate over the array using the for-each construct (also called the \"enhanced for\" loop):
f
No.
The for loop is just syntactic sugar. It behaves differently depending on whether or not it is applied to an Array argument or an object implementing the Iterable interface.
For Iterable objects, the loop expands to something like this:
Iterator iter = iterableObject.iterator();
while (iter.hasNext()) {
ArrayElement e = iter.next();
// do smth
}
What your example code is actually doing is something like this:
Object[] temp = Method.returnArray();
for ( int i = 0; i < temp.length; i++ ) {
ArrayElement e = (ArrayElement) temp[i];
// do smth
}