回归JDK源代码(2)Enumeration<E>接口
现在的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<E></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>的源代码和翻译之后,想必您和我都有同一个想法:这玩意并没有什么*用。
那么为什么我们还要去了解这个接口的源代码呢?作用就是、、、能够装逼。

回归JDK源代码(2)Enumeration<E>接口的更多相关文章
- 通过分析 JDK 源代码研究 TreeMap 红黑树算法实现
本文转载自http://www.ibm.com/developerworks/cn/java/j-lo-tree/ 目录: TreeSet 和 TreeMap 的关系 TreeMap 的添加节点 Tr ...
- JDK源代码学习系列04----ArrayList
JDK源代码学习系列04----ArrayList 1 ...
- JDK源代码学习系列05----LinkedList
JDK源代码学习系列05----LinkedList 1.LinkedList简单介绍 LinkedList是基于双向 ...
- 调试JDK源代码-一步一步看HashMap怎么Hash和扩容
调试JDK源代码-一步一步看HashMap怎么Hash和扩容 调试JDK源代码-ConcurrentHashMap实现原理 调试JDK源代码-HashSet实现原理 调试JDK源代码-调试JDK源代码 ...
- JDK源代码学习系列03----StringBuffer+StringBuilder
JDK源代码学习系列03----StringBuffer+StringBuilder 因为前面学习了StringBuffer和StringBuilder的父类 ...
- 无法debug断点跟踪JDK源代码——missing line number attributes的解决方法
在项目工程->Properties->Java Build Path->Libraries中导入的JRE System Library库里,给jar包添加JDK源代码包后,能够直接打 ...
- JDK源代码学习系列07----Stack
JDK源代码学习系列07----Stack 1.Stack源代码很easy ...
- eclipse Mars查看JDK源代码
eclipse Mars查看JDK源代码 问题描写叙述,eclipse(mars)下看不到JDK类的声明即源代码部分的内容. 如图右击string类型: 点击打开声明.结果出现了下图所看到的的错误,无 ...
- 如何调试JDK源代码并查看局部变量值
如下图: 按F5进入String.startsWith,如下: 点“Edit Source Lookup Path” 附加源代码,如下图: 附加上源代码后如下: 可以看到,当鼠标放在“prefix”上 ...
随机推荐
- js判断字符串是否有下划线
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 在服务器上使用 gradle 打包 android 源码
安装 android-tools mkdir ~/android && cd ~/android wget https://dl.google.com/android/reposi ...
- Forward链、Input链和Output链的区别
转载自:http://blog.chinaunix.net/uid-27863080-id-3442374.html 1. 如果数据包的目的地址是本机,则系统将数据包送往Input链.如果通过规则检查 ...
- office word使用技巧汇总
1.用MathType编辑的公式放在Word中有时会显示不全,仅显示其中一部分. 以下教程介绍解决Word中MathType公式显示不全的方法. 在Word中粘贴完公式后,选中该公式,在工具栏里选择“ ...
- js 的 一些操作。。。
// 对错误图片进行处理 $("img").error(function() { $(this).attr("src", "http://127.0. ...
- 【bzoj2935】[Poi1999]原始生物
2935: [Poi1999]原始生物 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 145 Solved: 71[Submit][Status][D ...
- BZOJ1725】[Usaco2006 Nov]Corn Fields牧场的安排 状压DP
Description Farmer John新买了一块长方形的牧场,这块牧场被划分成M列N行(1<=M<=12; 1<=N<=12),每一格都是一块正方形的土地.FJ打算在牧 ...
- 毕业设计 python opencv实现车牌识别 颜色定位
主要代码参考https://blog.csdn.net/wzh191920/article/details/79589506 GitHub:https://github.com/yinghualuow ...
- Go语言基础之8--面向对象编程1之结构体(struct)
一.结构体详解 1.1 声明和定义 1.Go中面向对象是通过struct来实现的, struct是用户自定义的类型 2.Go 语言中数组可以存储同一类型的数据,但在结构体中我们可以为不同项定义不同的数 ...
- Linux环境编程--waitpid与fork与execlp
waitpid waitpid(等待子进程中断或结束) 表头文件 #include<sys/types.h> #include<sys/wait.h> 定义函数 pid_t w ...