import java.util.Iterator; class Test { private final Iterator> i = null; public Foo next() { return new Bar<>(i.next()); } interface Foo {} private static class Bar implements Foo { Bar(Foo e) {} } }