在 Java 中使用 Deprecated 方法或类是错误的吗?

编程入门 行业动态 更新时间:2024-10-13 10:27:15
本文介绍了在 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.

我想知道一些事情

  • 在 Java 中使用已弃用的方法或类是错误的吗?

  • 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 方法或类是错误的吗?

    来自已弃用的定义:

    带有@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 方法或类是错误的吗?

    本文发布于:2023-10-24 20:31:01,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1524937.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:错误   方法   Java   Deprecated

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!