Named local classes are very rarely used, usually local classes are anonymous. Does anybody know why the code below generates a compiler warning?
public class Stuff<E> {
Iterator<E> foo() {
class InIterator implements Iterator<E> {
@Override public boolean hasNext() { return false; }
@Override public E next() { return null; }
@Override public void remove() { }
}
return new InIterator();
}
}
The warning is in new InIterator()
and it says
[unchecked] unchecked conversion
found : InIterator
required: java.util.Iterator<E>
If the class, unchanged, is made anonymous, or if it is made a member, the warning goes away. However, as a named local class, it requires a declaration class InIterator<E> implements ...
for the warning to go away.
What's going on?