本文介绍了已弃用API和旧版API之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java的 Collection Framework 中学习了遗留的API,我了解到 Vector code> HashTable 已被 ArrayList HashMap 取代。



然而,它们仍然不被弃用,并且被认为是遗留的,本质上,deprecation应用于被取代的软件功能,应该避免,所以,我不知道什么时候是API

解决方案

从官方Sun词汇表:

从弃用指南的使用方法:

@Deprecated 注释更进一步,警告危险:



参考资料












请注意,官方词汇表并没有定义legacy手段。很可能,这可能是Josh Bloch使用的一个术语,没有一个确切的定义。



也许一个旧的代码使用遗留但非过时的类



相反,弃用显式警告他们可能会停止






来自有效Java第2版的引用



为了比较这些术语在上下文中是如何使用的,这些是来自书的引用,其中出现了已过时的字:

/ em>出现:

这些引号未经过精心挑选:它们是所有包含已弃用字词 出现在书中。 Bloch的信息很清楚:




  • 已弃用的方法,例如 Thread.stop 是危险的,应该永远不会使用

  • ,例如 wait / notify 可以保留在旧代码中,但不应在新代码中使用。






我自己的主观意见



我的解释是,弃用的东西承认这是一个错误,从来没有好开始。另一方面,分类某事是一种遗产,承认它在过去是足够好,但它已经达到了它的目的,对于现在和未来来说已经不够好了。


I was studying the legacy API's in the Java's Collection Framework and I learnt that classes such as Vector and HashTable have been superseded by ArrayList and HashMap.

However still they are NOT deprecated, and deemed as legacy when essentially, deprecation is applied to software features that are superseded and should be avoided, so, I am not sure when is a API deemed legacy and when it is deprecated.

解决方案

From the official Sun glossary:

From the how-and-when to deprecate guide:

The @Deprecated annotation went a step further and warn of danger:

References


Note that the official glossary does not define what "legacy" means. In all likelihood, it may be a term that Josh Bloch used without an exact definition. The implication, though, is always that a legacy class should never be used in new code, and better replacement exists.

Perhaps an old code using legacy but non-deprecated class requires no action, since for now at least, they aren't in danger of ceasing to exist in future version.

In contrast, deprecation explicitly warns that they may cease to exist, so action should be taken to migrate to the replacement.


Quotes from Effective Java 2nd Edition

For comparison on how these terms are used in context, these are quotes from the book where the word "deprecated" appears:

By contrast, these are the quotes where the word "legacy" appears:

These quotes were not carefully selected: they're ALL instances where the word "deprecated" and "legacy" appear in the book. Bloch's message is clear here:

  • Deprecated methods, e.g. Thread.stop, are dangerous, and should never be used at all.
  • On the other hand, e.g. wait/notify can stay in legacy code, but should not be used in new code.

My own subjective opinion

My interpretation is that deprecating something is admitting that it is a mistake, and was never good to begin with. On the other hand, classifying that something is a legacy is admitting that it was good enough in the past, but it has served its purpose and is no longer good enough for the present and the future.

这篇关于已弃用API和旧版API之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 11:57