现在的Java程序员习惯使用Iterator<E>接口或者增强for循环来遍历集合。如果回到JDK 1.0,Enumeration接口则是遍历向量、哈希表的不二之选。本节就解读和翻译一下Enumeration<E>接口的源代码。当然,有一点还是得再强调一下:Enumeration<E>的泛型实在JDK 1.5时加上去的,最初的版本是没有泛型的。

package java.util;

/**
* An object that implements the Enumeration interface generates a
* series of elements, one at a time(一次一个). Successive calls to the
* <code>nextElement</code> method return successive(逐个) elements of the
* series.
* 实现了Enumeration接口的对象自动生成一系列元素,一次一个。
* 逐次调用nextElement()方法,依次返回系列元素。
* <p>
* For example, to print all elements of a <tt>Vector&lt;E&gt;</tt> <i>v</i>:
* 举例而言,打印Vector<V>中的所有元素
* <pre>
* for (Enumeration<E> e = v.elements(); e.hasMoreElements();)
* System.out.println(e.nextElement());</pre>
* <p>
* Methods are provided to enumerate through the elements of a
* vector, the keys of a hashtable, and the values in a hashtable.
* Enumerations are also used to specify the input streams to a
* <code>SequenceInputStream</code>
* <p>
* 所有的方法都被提供来枚举Vector、hashtable中的键、值的元素。
* Enumeration<E>也被用来指定一个到SequenceInputStream的输入流。
*
* NOTE: The functionality(功能) of this interface is duplicated by the Iterator
* interface. In addition, Iterator adds an optional remove operation, and
* has shorter method names. New implementations should consider using
* Iterator in preference to(优先于...) Enumeration.
* 提示:Enumeration<E>接口的功能已经被Iterator<E>接口赋复制。除此之外,Iterator<E>接口
* 添加了一个可选删除(元素)操作,以及更加简短的方法名。新的实现应该优先考虑使用Iterator<E>
* 接口,而非Enumeration<E>。
*
* @see java.util.Iterator
* @see java.io.SequenceInputStream
* @see java.util.Enumeration#nextElement()
* @see java.util.Hashtable
* @see java.util.Hashtable#elements()
* @see java.util.Hashtable#keys()
* @see java.util.Vector
* @see java.util.Vector#elements()
*
* @author Lee Boynton
* @since JDK1.0 历史遗留问题
*/
public interface Enumeration<E> {
/**
* Tests if this enumeration contains more elements.
* 测试是否此枚举还包含有元素。
* @return <code>true</code> if and only if this enumeration object
* contains at least one more element to provide;
* <code>false</code> otherwise.
* 当且仅当此枚举对象还有至少一个元素可以提供,返回true;否则,返回false。
*/
boolean hasMoreElements(); // 别少了s,老外写代码是很重视单复数滴 /**
* Returns the next element of this enumeration if this enumeration
* object has at least one more element to provide.
* 如果此枚举对象还有至少一个元素可以提供,那么返回此枚举的下一个元素。
* @return the next element of this enumeration.
* 返回此枚举的下一个元素
* @exception NoSuchElementException if no more elements exist.
* 如果没有更多的元素存在,抛出NoSuchElementException异常
*/
E nextElement();
}

阅读完Enumeration<E>的源代码和翻译之后,想必您和我都有同一个想法:这玩意并没有什么*用。

那么为什么我们还要去了解这个接口的源代码呢?作用就是、、、能够装逼。

最新文章

  1. 设计模式--代理模式Proxy(结构型)
  2. Ubuntu安装Gnome3
  3. 设置一个顺手的Xcode
  4. Java语言程序设计(基础篇) 第五章 循环
  5. Lua学习笔记一
  6. [SAP ABAP开发技术总结]选择屏幕——各种屏幕元素演示
  7. java 单例设计模式
  8. Android --Fragment中异步HTTP请求
  9. hdu 1427 dfs
  10. C++ 智能指针auto_ptr详解
  11. winfrom 底层类 验证码 分类: C# 2014-12-17 11:18 258人阅读 评论(0) 收藏
  12. volatile详解
  13. linux系统性能监控常用命令
  14. A Game of Thrones(20) - Eddard
  15. 织梦dedecms列表页dede:pagelist分页问题
  16. div+css命名规范大全
  17. Java集合干货——ArrayList源码分析
  18. OTG驱动分析(一)
  19. 【转】火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换算法
  20. Asp.net 子域共享cookie

热门文章

  1. 二叉树的遍历 &amp;【NOIP2001普及组】&amp; 洛谷 P1030 求先序排列
  2. 【STL基础】deque
  3. vs已停止工作的解决方案
  4. P4245 【模板】任意模数NTT
  5. DP小题集
  6. form组件之modelForm
  7. JDK Integer
  8. javascript中对两个对象进行排序 和 java中的两个对象排序
  9. MySQL之concat以及group_concat的用法
  10. thinkPHP5.0获取器