已弃用的内容在JDK中

huangapple go评论77阅读模式
英文:

Deprecated content in JDK

问题

为什么在JDK中仍然存在像Thread.stop()这样的废弃内容?

在文档网站这里,我可以看到该方法被标记为

> @Deprecated(since="1.2")

自1.2版本以来!

另外,还有一条说明:

这个方法本质上是不安全的

那么为什么它仍然存在呢?废弃代码的存在可能会导致许多问题。

英文:

Why is there still deprecated content in JDK like Thread.stop()?

On the documentation site here I can see the method is

> @Deprecated(since="1.2")

Since 1.2!

Also, there is a note:

This method is inherently unsafe

So why is it still there? The presence of deprecated code can potentially lead to many issues.

答案1

得分: 2

以下是已翻译的内容:

有一整页关于 Oracle 讨论 API 弃用的内容如果你想阅读,但这里有一个很好的摘录,总结了为什么弃用函数仍然存在于 Java 中:

弃用在所有这些情况下都是一个合理的选择,因为它保留了“向后兼容性”,同时鼓励开发人员切换到新的 API。此外,弃用的注释帮助开发人员决定何时迁移到新的 API,因此应简要提到弃用的技术原因。

最终,它将被移除,但在足够有信心的情况下,人们不再使用仍然使用 Thread.stop() 的程序之前,它将保留在那里,只是让人们知道有更好的选择。

英文:

There is a whole page from Oracle talking about deprecation in APIs if you want to read about it, but here is a good snippet which sums up why deprecated functions are still in Java:

> Deprecation is a reasonable choice in all these cases because it preserves "backward compatibility" while encouraging developers to change to the new API. Also, the deprecation comments help developers decide when to move to the new API, and so should briefly mention the technical reasons for deprecation.

Eventually, it will be removed, but until there is enough confidence that people are not using programs that still utilse Thread.stop(), they will keep it in there, and just let people know that there are much better options to choose from.

huangapple
  • 本文由 发表于 2020年8月2日 21:53:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/63216808.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定