Vector 是一个过时的集合 [英] Vector is an obsolete Collection

查看:18
本文介绍了Vector 是一个过时的集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

检查报告对 java.util.Vector 或 java.util.hashtable 的任何使用.虽然仍受支持,但这些类已被 JDK 1.2 集合类淘汰,可能不应在新的开发中使用....

The Inspection reports any uses of java.util.Vector or java.util.hashtable. While still supported, these classes were made obsolete by the JDK 1.2 Collection classes and should probably not be used in new Development....

我有一个 Java 项目,它使用 无处不在,我使用的是最新的 JDK 8.我想知道我是否可以在最新的 Java 上运行该应用程序.

I have a project in Java which uses vector Everywhere, and I'm using JDK 8 which is the latest one. I want to know if I can run that application on latest java.

并告诉我是否可以对 ArrayList 使用其他关键字,例如用于 new java 的 Vector.

And tell if i can use some other keyword for ArrayList like Vector for new java.

推荐答案

首先,虽然 Vector 大部分被 ArrayList 淘汰,但使用它仍然是完全合法的,您的项目应该可以正常运行.

First of all, although Vector is mostly obsoleted by ArrayList, it is still perfectly legal to use, and your project should run just fine.

然而,如上所述,不建议使用.这样做的主要原因是它的所有方法都是 synchronized,这通常是无用的,并且会显着降低您的应用程序的速度.任何未在方法范围之外共享的局部变量都可以安全地替换为 ArrayList.方法参数、返回值和数据成员在被替换为 ArrayList 之前应仔细检查,以免您无意中更改同步语义并引入难以发现的错误.

As noted, however, it is not recommended to use. The main reason for this is that all of its methods are synchronized, which is usually useless and could considerably slow down your application. Any local variable that's not shared outside the scope of the method can safely be replaced with an ArrayList. Method arguments, return values and data members should be inspected closely before being replaced with ArrayList, lest you unwittingly change the synchronization semantics and introduce a hard-to-discover bug.

这篇关于Vector 是一个过时的集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆