0

I implementing a linkedlist with generics. But I'm getting "Multiple markers at this line - The type MyIterator is not generic; it cannot be parameterized with arguments " at the return statement. Figure is an interface

public Iterator<Figure> iterator() {

    class MyIterator implements Iterator<Figure> {
        private Node current;

        private MyIterator(Node n) {
            current = n;
        }

        public boolean hasNext() {
            return current.next != null;
        }

        public Figure next() throws NoSuchElementException {
            if (current.next == null)
                throw new NoSuchElementException();
            current.setNext(current.next);
            Object c=current;
            return (Figure) c;
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }

    }

    return new MyIterator<Figure>();
}

1 Answer 1

2

Clearly MyIterator is not generic. You've use it like generic type. Change your return statement to:

return new MyIterator();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.