开发者

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

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[keysCo开发者_如何学Cllection.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.


Backpack doesn't implement it. The anonymous inner class used in getEnumeration does. If you want Backpack itself to implement Enumeration, it needs to have those methods.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜