Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Iterator Type Reverts to java.lang.Object

843793Jul 9 2006 — edited Jul 10 2006
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?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 7 2006
Added on Jul 9 2006
5 comments
167 views