I have the following iterator implementation:
public abstract class SomeCollection<T> {
protected ArrayList<T> items = new ArrayList<T>();
public Iterator<T> iterator() {
return new Iterator<T>() {
int currentItem = -1;
public boolean hasNext() { ... }
public T next() { return items.get(++currentItem);}
public void remove() { ... }
};
}
}
However, when I try to use the iterator in the following method:
for (someType item : someCollection) {
...
}
I get the error for incompatible types, where java.lang.Object is found when someType is required.
Any idea, anyone?