为什么Stack在JDK中扩展Vector? [英] Why Stack extends Vector in JDK?

查看:102
本文介绍了为什么Stack在JDK中扩展Vector?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Stack 不是 Vector 那么为什么Stack类正在扩展(是一种关系)JDK中的Vector类, Stack假设使用 push()& pop()操作,但因为它扩展了Vector我可以做 add() remove()堆栈上的操作。

Stack is not a Vector then why Stack class is extending(is a relationship) Vector class in JDK, Stack suppose to work with push() & pop() operations, but because it extends Vector I am able to do add() and remove() operations over a stack.

我认为宁可扩展Vector类,Stack类应该使用Vector类作为组合。

I think rather extending Vector class, Stack class should use Vector class as a composition.

推荐答案

过时的课程



两者 Stack Vector 。由于当时的互联网狂潮,Java被赶到了市场之前。

Outmoded classes

Both Stack and Vector were included with the first release of Java. Java was rushed to market ahead of its time because of the Internet frenzy at that time.

与最早版本的Java捆绑在一起的一些类,例如日期时间类,没有经过深思熟虑。他们没有受到同行评审和公众监督,因为后来的图书馆,例如通过 JAva社区制作的图书馆流程以及开源项目和行业联盟项目。

Some of the classes bundled with those earliest versions of Java, such as the date-time classes, were not well thought-out. They had not been subjected to peer review and public scrutiny as were later libraries such as some produced through the JAva Community Process and through open-source projects and industry consortium projects.

Java Collections框架取代了这两个类。同样, java.time 框架取代旧的日期时间类,例如 java.util.Date / .Calendar 。旧类保留在Java中以便与现有应用程序向后兼容,但不应在新代码中使用。

The Java Collections framework supplants both of these classes. Similarly, the java.time framework supplants the old date-time classes such as java.util.Date/.Calendar. The old classes remain in Java for backwards compatibility with existing apps but should not be used in new code.

Stack 类文档告诉你这个,清楚地说你应该使用 <$ c $的实现c> Deque 界面。

这篇关于为什么Stack在JDK中扩展Vector?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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