是否有人仍在使用 Vector(而不是 Collections.synchronizedList(List list)/CopyOnWriteArrayList)?
我想知道为什么 这个问题在 2011 年 J2SE 1.2 中仍然存在于 98 年 12 月与 Collections 框架一起发布。是否有人仍在使用 Vector(除非您正在为返回 Vector 的接口编写客户端)?
I wonder why this question still exists in 2011,J2SE 1.2 was released in Dec 98 with Collections framework.is there anybody out there still using Vector(unless you are writing client for interface that returns Vector)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Java 5.0 在 2004 年引入了并发集合,许多人似乎并没有使用它们来代替 Collections.synchronizedList()。它们不是直接替代品,有时使用 JDK 1.2 或 5.0 集合更好,但令我惊讶的是,人们经常没有很好地利用它们。
Java 5.0 introduce the concurrency collections in 2004, and many people don't appear to be using these instead of Collections.synchronizedList(). They are not a direct replacement, sometimes it is better to use the JDK 1.2 or 5.0 collections but it surprised me how often people don't make good use of them.
我已经很多年没有使用 Vector 或 Hashtable 了。
I haven't used Vector or Hashtable in many years now.
Vector
和Hashtable
等遗留集合类仍然存在,因为 Sun(现在是 Oracle)始终认为保持 Java 向后兼容极其重要。他们从不从标准 Java API 中删除旧的东西,因为那会破坏旧的程序。真正的问题应该是:为什么 Sun(或 Oracle)没有弃用遗留集合类?
没有明确的技术原因说明为什么旧类没有被弃用。可能这是因为 API 的其他部分仍在使用这些遗留类,并且 Sun / Oracle 不想在编译期间用弃用警告过多地打扰用户。
不管怎样,永远不要使用那些遗留类,除非你真的必须这样做(例如因为你正在处理旧的 API)。
Legacy collection classes such as
Vector
andHashtable
still exist because Sun (and now Oracle) always deemed it extremely important to keep Java backwards compatible. They never remove old stuff from the standard Java API, because that would break old programs.The real question should be: Why did Sun (or Oracle) not make the legacy collection classes deprecated?
There isn't a clear technical reason why the old classes are not deprecated. Probably this is because other parts of the API are still using those legacy classes and Sun / Oracle don't want to bother users too much with deprecation warnings during compilation.
Anyway, never use those legacy classes unless you really have to (for example because you're dealing with an old API).
我经常将 Vector 与 Swing 一起使用。我有很多使用像 DefaultTableModel 这样的类的应用程序,如果您在 Vector 中有数据,那么使用这些类非常简单。有很多方法可以解决这个问题,但我喜欢保持简单,因为它不会影响性能。
然而,任何其他时候我需要一个列表时我不会使用 Vector。
I use Vector frequently mostly with Swing. I have a lot of applications that use classes like DefaultTableModel that are really simple to use if you have data in a Vector. There are ways around this, but I like to keep simple as it does not hinder performance.
However, any other time I need a list I do not use Vector.