在Java中使用Deprecated方法或类是不对的? [英] Is it wrong to use Deprecated methods or classes in Java?

查看:330
本文介绍了在Java中使用Deprecated方法或类是不对的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用eclipse开发一个Web应用程序。就在今天,我通过更改JAR文件更新了我的struts版本。我在一些地方收到警告,方法已被弃用,但代码工作正常。

I am using eclipse to develop a web application. Just today I have updated my struts version by changing the JAR file. I am getting warnings at some places that methods are deprecated, but the code is working fine.

我想知道一些事情


  1. 在Java中使用不推荐使用的方法或类是不对的?

  1. Is it wrong to use Deprecated methods or classes in Java?

如果我不知道怎么办?更改任何方法并使用我的警告运行我的应用程序,它是否会产生任何性能问题。

What if I don't change any method and run my application with warnings that I have, will it create any performance issue.


推荐答案


1。在Java中使用不推荐使用的方法或类是不对的?

来自已弃用的定义


注释@Deprecated的程序元素是程序员不鼓励使用的程序元素,通常是因为它很危险,或者因为存在更好的替代方案。

该方法保留在API中,以便在未指定的时间段内向后兼容,并可能在将来的版本中删除。也就是说,不,它不是错误,但有一种更好的方法,它可以更好地抵御API更改。

The method is kept in the API for backward compatibility for an unspecified period of time, and may in future releases be removed. That is, no, it's not wrong, but there is a better way of doing it, which is more robust against API changes.


2。如果我不更改任何方法并使用我的警告运行我的应用程序会产生任何性能问题。

很可能没有。它将继续像弃用之前一样工作。 API方法的合同不会改变。如果某些内部数据结构改变而采用新的更好的方法,可能会对性能产生影响,但这种可能性很小。

Most likely no. It will continue to work as before the deprecation. The contract of the API method will not change. If some internal data structure changes in favor of a new, better method, there could be a performance impact, but it's quite unlikely.

Java API中的最有趣的弃用是imo, FontMetrics.getMaxDecent 。弃用原因:拼写错误。

The funniest deprecation in the Java API, is imo, the FontMetrics.getMaxDecent. Reason for deprecation: Spelling error.


已弃用。从JDK版本1.1.1开始,由getMaxDescent()替换。

这篇关于在Java中使用Deprecated方法或类是不对的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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