我对枚举感到困惑

发布于 2024-08-20 13:52:57 字数 81 浏览 3 评论 0原文

如果从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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

删除→记忆 2024-08-27 13:52:57

枚举是早期的 Java 类基本上被 Iterator。它用于迭代某些很大程度上过时的集合。

枚举 是 Java 版本的类型安全枚举C/C++ 意义。它们代表一组有限且固定的值,这些值是规范的,但也可以具有行为。它们源于 Joshua Bloch 在 Effective Java

换句话说,他们没有关系。

Enumeration is an early Java class essentially replaced by Iterator. 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.

盛装女皇 2024-08-27 13:52:57

java.util.Enumeration 是 java.util.Iterator 的前身,在 Java 1.2 中引入。下面是 Javadoc 中用于迭代 Vector 的 Enumeration 的示例,

for (Enumeration<E> e = v.elements(); e.hasMoreElements();)
   System.out.println(e.nextElement());

它与 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

for (Enumeration<E> e = v.elements(); e.hasMoreElements();)
   System.out.println(e.nextElement());

It has nothing to do with Java 5 enums.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文