[英]Enumeration hasMoreElements() returns false
I do this in my code: 我在我的代码中执行此操作:
Enumeration liste = attribut.getListe ();
if (liste != null) {
while (liste.hasMoreElements ()) {
...
I have one element in my Enumeration but when I inspect liste.hasMoreElements ()
, why does it return false
? 我的Enumeration中有一个元素但是当我检查
liste.hasMoreElements ()
,为什么它返回false
?
I would have getListe()
always return a collection (empty or otherwise) and only use an Iterator. 我会让
getListe()
总是返回一个集合(空或其他)并且只使用Iterator。
eg 例如
for(Entry e: getListe()) {
// do something with e.
}
Instead of creating an empty list you can use Collections.emptyList() (and other empty collections) 您可以使用Collections.emptyList() (以及其他空集合)而不是创建空列表
If your Enumeration should have an element but doesn't, it would suggest you have a bug in getListe() 如果您的Enumeration应该有一个元素但是没有,那么它会建议您在getListe()中有一个错误
Have you already iterated the enumeration? 你已经迭代了枚举了吗? Ie does getListe() return a new element list?
即getListe()返回一个新的元素列表?
From the javadoc: 来自javadoc:
for (Enumeration e = v.elements() ; e.hasMoreElements() ;) {
System.out.println(e.nextElement());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.