public interface NamingEnumeration<T> extends Enumeration<T>
当一个方法如list(),listbindings(),或()返回NamingEnumeration,遇到任何例外保留直到所有结果返回。在枚举的结尾,异常抛出(由hasmore());
例如,如果list()还只是答案的一部分,相应的异常会partialresultexception。list()首先会返回一个namingenumeration。当结果最后被namingenumeration的next()返回,调用hasmore()会导致partialresultexception抛出。
另一个例子中,如果()方法调用指定的大小限制的“n”。如果答案是超过n()会返回一个结果,第一namingenumeration。当第n个结果被调用next()在namingenumeration回来,一sizelimitexceedexception就扔在hasmore()调用。
注意:如果程序使用hasmoreelements()和nextelement()相反遍历namingenumeration,因为这些方法不能抛出异常,无异常将被抛出。相反,在前面的例子中,在n个结果已经返回nextelement(),调用hasmoreelements()会返回false。
注意,如果程序调用NoSuchElementException next()或nextelement()当有枚举中没有元素。该程序可以通过使用hasmore()和hasmoreelements()是否枚举的结尾已经达到避免这种例外。
如果在枚举过程中抛出异常,枚举将无效。在该枚举的任何方法的后续调用将产生未定义的结果。
Modifier and Type | Method and Description |
---|---|
void |
close()
关闭此枚举。
|
boolean |
hasMore()
确定枚举中是否有更多的元素。
|
T |
next()
检索枚举中的下一个元素。
|
hasMoreElements, nextElement
T next() throws NamingException
注意,next()也抛出运行时异常NoSuchElementException表明来访者试图枚举无法枚举的结尾。这是不同于namingexception,它表示在获取下一个元素,一个问题为例,由于转诊或服务器不可用,等。
NamingException
-如果一个命名的例外是在试图获取下一个元素中。看到namingexception和可能的命名异常的子类。
NoSuchElementException
如果试图获得下一个元素时,不可用。
Enumeration.nextElement()
boolean hasMore() throws NamingException
NamingException
-如果一个命名的例外是在试图确定是否有枚举中的另一个元素中。看到namingexception和可能的命名异常的子类。
Enumeration.hasMoreElements()
void close() throws NamingException
此方法向服务提供商表示,它是免费发布与枚举相关的资源的资源,并可以通知服务器取消任何未完成的请求。的close()法是一种暗示,实现管理资源。实施鼓励使用合适的算法来管理他们的资源时,客户端调用了close()。
NamingException
-如果一个命名的例外是在关闭枚举遇到。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.