Reputation: 21
I have a problem with an interface. I have an Iterator interface like this:
package com.wrox.algorithms.iteration;
import com.wrox.algorithms.lists.IteratorOutOfBoundsException;
public interface Iterator {
public void first();
public void last();
public void isDone();
public void next();
public Object current() throws IteratorOutOfBoundsException;
}
After that I create test class and test the iteration in an empty list:
package com.wrox.algorithms.lists;
import com.wrox.algorithms.iteration.Iterator;
.....
public void testForwardIteration() {
Lists list = createList();
Iterator iterator = list.iterator(); // <- ERROR
}
I get this error:
Type mismatch: cannot convert from java.util.Iterator to com.wrox.algorithms.iteration.Iterator
Have you any idea where my mistake is? Thank you for your support!
Upvotes: 0
Views: 1359
Reputation: 50031
If two people have the same name, that doesn't mean you can pretend they are the same person. They're still two separate people. You can be friends with both, but if you mix them up they will be annoyed with you.
Similarly, if two interfaces are named Iterator
, that doesn't mean you can pretend they are the same interface. java.util.Iterator
and com.wrox.algorithms.iteration.Iterator
are two separate interfaces. You can use both, but if you mix them up the compiler will yell at you.
Upvotes: 0
Reputation: 899
list.iterator() returns a java.util.Iterator, not a com.wrox.algorithms.iteration.Iterator
Edit: Just noticed you have a "Lists" and not a "List". You also need a List from java.util.List. Don't create your own List/Lists
Upvotes: 3