I am implementing an interface I on a class A.Class A implements I.I have an Iterator T that is supposed to return an object which implements I everytime I call next.My iterator goes as follows (of course omitting other stuff):public class T<I> implements Iterator<I> {            @Override    public I next() {        return new A();    }    }However, I get this error: Required I, found A (for the return new A() line)....I don't know what is happening. Can someone help me?
Why can't I return an implementation of an interface for a method that requests the interface?
java;interfaces;iterator
Your class definition introduces I as a type variable, meaning that it does not refer to the interface you expect it to. Change your class definition topublic class T implements Iterator <I>and everything should work fine.