Results 1 to 4 of 4
  1. #1
    nolsen01 is offline Member
    Join Date
    Jul 2009
    Posts
    18
    Rep Power
    0

    Default constructor won't work.

    I created a class called ReverseIterator:

    Java Code:
    public class ReverseIterator implements Iterator{
    
        private Iterator _iterator;
    
        public void ReverseIterator(Iterator iterator){
            assert iterator != null : "iterator can not be null";
            _iterator = iterator;
        }
    }
    When I try to write the unit test for this class, I have
    Java Code:
    ReverseIterator iterator = new ReverseIterator(new ArrayIterator(array));
    and it will not accept it.

    ArrayIterator implements Iterator just like ReverseIterator does so shouldn't I be able to pass an ArrayIterator to ReverseIterators constructor?
    Last edited by nolsen01; 09-13-2010 at 05:54 PM.

  2. #2
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

    Default

    constructors should return nothing, not even void.

    public ReverseIterator (Iterator iterator)

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

    Default

    Your constructor isn't a constructor as it has a void return type. Constructors have no return type at all.

    Edit: As BB said above. I'm a little slow today.

  4. #4
    nolsen01 is offline Member
    Join Date
    Jul 2009
    Posts
    18
    Rep Power
    0

Similar Threads

  1. Constructor
    By arefeh in forum New To Java
    Replies: 9
    Last Post: 01-11-2010, 11:38 AM
  2. Constructor
    By Sarinam in forum AWT / Swing
    Replies: 1
    Last Post: 06-19-2008, 08:03 AM
  3. Replies: 0
    Last Post: 12-19-2007, 09:10 AM
  4. Replies: 0
    Last Post: 12-19-2007, 09:01 AM
  5. Constructor Help
    By bluegreen7hi in forum New To Java
    Replies: 2
    Last Post: 11-15-2007, 05:44 AM

Posting Permissions

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