Eclipse 说我没有实现枚举,但我实现了
大家早上好,
我在学校项目上遇到了一些问题。 我们被告知要创建一个迭代器来实现哈希映射上的枚举。
所以我做了这个枚举:
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++]);
}
};
}
这在我的 Backpack 类中
public class Backpack extends Item implements Carrier, Enumeration<Object>{
哈希图由 getContent() 返回。现在的问题是 eclipse 一直告诉我我还没有实现枚举中的方法。如果我使用快速修复,它只会在我的类中添加 hasMoreElements() 和 nextElement() 虚拟方法。 不知怎的,它在内部类中看不到这些方法。
任何人都可以帮助我吗?任何帮助表示赞赏。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Backpack
没有实现它。getEnumeration
中使用的匿名内部类可以做到这一点。如果你想让Backpack本身实现Enumeration,它需要有这些方法。Backpack
doesn't implement it. The anonymous inner class used ingetEnumeration
does. If you want Backpack itself to implement Enumeration, it needs to have those methods.