Eclipse says I don't implement Enumeration, but I do

Posted by Harm De Weirdt on Stack Overflow See other posts from Stack Overflow or by Harm De Weirdt
Published on 2010-05-30T06:42:18Z Indexed on 2010/05/30 6:52 UTC
Read the original article Hit count: 418

Goodmorning everybody,

I'm having a little problem with a project for school. We are told to make an Iterator that implements Enumeration over a Hashmap.

So i made this Enumeration:

public Enumeration<Object> getEnumeration() {
        return new Enumeration<Object>() {
            private int itemsDone = 0;
            Collection<Long> keysCollection = getContent().keySet();            
            Long [] keys = keysCollection.toArray(new Long[keysCollection.size()]);


            @Override
            public boolean hasMoreElements() {
                if(itemsDone < getContent().size() +1 ) {
                    return true;
                }else {
                    return false;
                }

            }
            @Override
            public Object nextElement() {               
                return getContent().get(keys[itemsDone++]);
            }
        };
    }

This goes in my Backpack class

public class Backpack extends Item implements Carrier, Enumeration<Object>{

The hashmap is returned by getContent(). The problem now is that eclipse keeps telling me I havent implemented the methods from Enumeration. If I use the quick fix it just adds the hasMoreElements() and nextElement() dummy methods in my class. Somehow it doesn't see these methods in the inner class..

Can anyone help me please? Any help is appreciated.

© Stack Overflow or respective owner

Related posts about homework

Related posts about enumeration