Results 1 to 3 of 3

Thread: iteratorHelper

  1. #1
    therealyacek is offline Member
    Join Date
    Oct 2012
    Posts
    8
    Rep Power
    0

    Exclamation iteratorHelper

    I'm getting an error in the iteratorHelp() method

    Java Code:
       public Iterator<E> iterator() {
    		return new IteratorHelper();
    	}
    	
    	class IteratorHelper<E> implements Iterator<E> {
    		Node<E> iteratorPointer;
    		
    		public IteratorHelper() {
    			iteratorPointer = head;
    		}
    		
    		public boolean hasNext() {
    			return iteratorPointer != null;
    		}
    		
    		public E next() {
    			if(!hasNext())
    				throw new NoSuchElementException();
    			E tmp = iteratorPointer.data;
    			iteratorPointer = iteratorPointer.next;
    			return tmp;
    		}
    		
    		public void remove() {
    			throw new UnsupportedOperationException();
    		}
    	}
    iteratorPointer = head;

    error: incompatible types

    but they are of the same type

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: iteratorHelper

    Please show where you declare head. Please show the actual and complete compiler error message.

  3. #3
    therealyacek is offline Member
    Join Date
    Oct 2012
    Posts
    8
    Rep Power
    0

    Default Re: iteratorHelper

    I got it actually

    should be

    Java Code:
    class IteratorHelper implements Iterator<E>
    not
    Java Code:
    class IteratorHelper<E> implements Iterator<E>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •