Type mismatch: cannot convert from Item to Item

后端 未结 1 1908
public class RandomizedQueue implements Iterable {

    private Item[] s;
    private int N;

    public Iterator iterator() {
           


        
1条回答
  •  伪装坚强ぢ
    2021-01-15 16:19

    Your inner class RQIterator is declaring a new type parameter Item that is distinct from the type parameter Item that its enclosing class RandomizedQueue is declaring.

    However, the Item type parameter from RandomizedQueue is still in scope, because RQIterator, as a nested class, isn't a static nested class. Just use Item from RandomizedQueue.

    private class RQIterator implements Iterator {
    

    Also the creation of the iterator in iterator() won't need the type parameter either.

    public Iterator iterator() {
        return new RQIterator();
    }
    

    0 讨论(0)
提交回复
热议问题