I know an enhanced for-loop (since java 1.5) can be used to iterate over collections of class-types that implement the Iterator interface. It can however also be used to iterate over arrays of primitive types e.g. int, boolean,... So my logical conclusion was that thanks to autoboxing and unboxing, for example, primitve integers were being wrapped inside their reference-type which would then on their turn, implement Iteratable.
However, when I looked up the documentation of java.lang.Integer
, nowhere is mentioned any extension or implementation of a superclass or interface that could implement or extend the Iterable
interface. How does an enhanced for-loop know how to loop over primitive types without the Iterable
interface being implemented?