import java.util.Iterator;
public class Main {
public static class ShouldBeIterable<T> implements Iterable<Integer> {
@Override
public Iterator<Integer> iterator() {
return null;
}
}
public static void main(String[] args) {
ShouldBeIterable it = new ShouldBeIterable();
for (Integer i : it) {
System.out.println("Bla");
}
}
}
The code above compiles with following error:
Error:(17, 26) java: incompatible types: java.lang.Object cannot be converted to java.lang.Integer
However, if I generify it with practically any type (even Object), the error disappears.
Why? How does it work? How can I solve this issue without using generics?