duff said:
Compile time error with that example.
It must be quite recent as generics was used on that page.
Did you replace the ... parts with appropriate "null" returns? If i do
that, it compiles fine for me.
Also note that the StackIterator class is not a local class, but an
inner class of Stack. If it where a local class the code would look
like this:
public class Stack {
private ArrayList<Object> items;
//code for Stack's methods and constructors
//not shown
public Iterator<Object> iterator() {
class StackIterator implements Iterator {
int currentItem = items.size() - 1;
public boolean hasNext() {
return false; // implement!
}
public ArrayList<Object> next() {
throw new NoSuchElementException // implement!
}
public void remove() {
throw new UnsupportedOperationException();
}
}
return new StackIterator();
}
}