我对枚举感到困惑
如果从jdk1.5开始使用枚举,那么java.util.Enumeration接口有什么用 jdk1.5之前?有人可以帮我举个例子来探讨这个问题吗?
If enums are used from jdk1.5 onwards , what was the use of java.util.Enumeration interface
before jdk1.5 ? Can anybody help me explore this with an example please ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
枚举
是早期的 Java 类基本上被Iterator
。它用于迭代某些很大程度上过时的集合。
枚举 是 Java 版本的类型安全枚举C/C++ 意义。它们代表一组有限且固定的值,这些值是规范的,但也可以具有行为。它们源于 Joshua Bloch 在 Effective Java。
换句话说,他们没有关系。
Enumeration
is an early Java class essentially replaced byIterator
. it is used for iteration of certain largely outdated collections.Enums are Java's version of typesafe enums in the C/C++ sense. They represent a finite and fixed set of values that are canonical but can also have behaviour. They stem from the pattern established by Joshua Bloch in Effective Java.
In other words, they're not related.
枚举
和java.util.Enumeration< /code>
不相关。
Enum
andjava.util.Enumeration
are unrelated.java.util.Enumeration 是 java.util.Iterator 的前身,在 Java 1.2 中引入。下面是 Javadoc 中用于迭代 Vector 的 Enumeration 的示例,
它与 Java 5 枚举无关。
java.util.Enumeration was the precursor to java.util.Iterator which was introduced in Java 1.2. Below is an example from the Javadoc of an Enumeration being used to iterate through a Vector
It has nothing to do with Java 5 enums.