I have a class MyDoublyIterator<E> that implements the Iterator<E> interface. Also, it has a couple other methods not part of the interface (for example public void boolean hasPrev()). When I try to call that method in my main class my IDE can’t resolve that method.
Here’s the code I’m using to call it
Iterator<String> di = new MyDoublyIterator<String>();
di.hasPrev();
So I guess my question why can’t it find that method. Do I have to build an abstract class that implements the interface and extend it?
The Problem is that the di-variable is of the type Iterator. So it could contain any implementation of this interface. And therefore the IDE cannot be sure that it contains an instance of MyDoublyIterator. So to make it work like you requested, you have to change the type of the variable to MyDoublyIterator.