deprecated_@Deprecated新外观可能是什么?

deprecated

JDK增强建议 (JEP)277(“ 增强的弃用 ”)建议“重新定义弃用注释,并提供加强功能生命周期尾端的工具。” 当前@ java.lang.Deprecated的一些限制使我困扰了一段时间。 我特别希望能够使用@Deprecated提供文本,而不是被迫在相应的Javadoc @deprecated注释中放置说明性文本。 在这篇文章中,我看了一个自定义批注,它给人一种JEP 277提议包含在新的改进的@Deprecated批注中的额外元数据类型的感觉。

dustin.examples.annotations.Deprecated的代码清单包含dustin.examples.annotations.Deprecated的定义,该实现主要反映JEP 277提案中描述的内容。

不推荐使用dustin.examples.annotations。

package dustin.examples.annotations;import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.ElementType.TYPE;/*** Conceptual improvement on standard @java.lang.Deprecated annotation* based on preliminary discussion related to JEP 277 and on* desire to include context details with deprecation annotation* rather than relying on presence of Javadoc's @deprecated.** Javadoc comments in this annotation definition are largely* based on descriptions in JEP 277 (http://openjdk.java.net/jeps/277).*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({CONSTRUCTOR,FIELD,LOCAL_VARIABLE,METHOD,PACKAGE,PARAMETER,TYPE})
public @interface Deprecated
{/*** JEP 277-defined reasons and associated explanations.*/public enum Reason{/*** This API has been deprecated without any reason having been given.* This is the default value; everything that's deprecated today* implicitly has a deprecation reason of UNSPECIFIED.*/UNSPECIFIED,/*** This API is earmarked for removal in a future JDK release. Note,* the use of the word "condemned" here is used in the sense of a* structure that is intended to be torn down. The term is not mean* to imply any moral censure.*/CONDEMNED,/*** Use of this API can lead to data loss, deadlock, security* vulnerability, incorrect results, or loss of JVM integrity.*/DANGEROUS,/*** This API is no longer necessary, and usages should be removed.* No replacement API exists. Note that OBSOLETE APIs might or* might not be marked CONDEMNED.*/OBSOLETE,/*** This API has been replaced by a newer API, and usages should be* migrated away from this API to the newer API. Note that SUPERSEDED* APIs might or might not be marked CONDEMNED.*/SUPERSEDED,/*** Calling this has no effect or will unconditionally throw an exception.*/UNIMPLEMENTED,/*** This API is not a stable part of the specification, and it may* change incompatibly or disappear at any time.*/EXPERIMENTAL;}/*** Provides any combination of one or more of the enum constants,* although not all combinations make sense. It is syntactically possible,* though perverse, to provide an empty array. Such a case should be* treated as if UNSPECIFIED were present.** @return One or more Reasons for deprecation; default value is the enum*    constant UNSPECIFIED and absence of values should be treated as such.*/Reason[] value();/*** Provides Strings representing any APIs that replace this API.* This should not specify any replacements if reason is OBSOLETE.** @return Strings returned by this method should be links to replacement*    APIs for the API being deprecated. Each string should be in the same*    format as the @link Javadoc tag.*/String[] replacement();/*** Provides the release in which the API was deprecated.** @return Release number at which this API became deprecated*    in a free-form syntax String with the release numbering*    following the same scheme as the @since Javadoc tag.*/String since();/*** Provides the anticipated complete removal of this deprecated API* if any known date or version is anticipated for the API's removal.* This value is most likely to be set for reasons of CONDEMNED,* OBSOLETE, and SUPERSEDED. This value is NOT described in JEP 277.** @return Date or version in which it is anticipated that this*    API will be removed altogether.*/String anticipatedRemoval() default "Not Planned";
}

下一个代码清单提供了将上述注释应用于不推荐使用的类的示例。

DeprecatedClass.java:使用改进的@Deprecated的示例

package dustin.examples.annotations.demo;import java.text.DateFormat;
import java.text.SimpleDateFormat;import static dustin.examples.annotations.Deprecated.Reason.*;/*** Demonstrates how new and improved @Deprecated might be used.*/
@dustin.examples.annotations.Deprecated(value={SUPERSEDED, CONDEMNED},since="1.5", anticipatedRemoval="1.9",replacement="dustin.examples.annotations.demo.OtherClass")
public class DeprecatedClass
{final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");@dustin.examples.annotations.Deprecated(value={DANGEROUS}, since="1.0",replacement="java.text.SimpleDateFormat#SimpleDateFormat")public DateFormat getDateFormatter(){return dateFormat;}
}

最后一个示例演示了改进的@Deprecated注释的@Deprecated 。 该“ anticipatedRemoval中的”元素@Deprecated注释不JEP 277中提到,我给它一个默认值,其中,过时的构造可能没有预期的拆除日期,而是已被弃用,以吓退只有它的新用途的情况。

上面的代码清单演示了定义一个新的和改进的@Deprecated批注(例如JEP 277中阐明的注释)。但是,JEP 277提出的远远不止一个改进的批注。 该提案还讨论了“运行时更改”,以提供“关于在选择加入的基础上使用已弃用API的警告”,“依赖工具增强”,以类似于jdeps工具甚至可能基于jdeps工具的方式分析注释依赖,以及“ Javadoc增强功能。”

尽管Java的自定义注释支持使实现@Deprecated的版本很容易实现,该版本反映了JEP 277中的许多思想,但是经过改进的新版@java.lang.Deprecated将具有许多自定义Java注释不具备的优点,例如内置-JDK中的-in支持并由JDK类使用。 由JDK提供的@Deprecated也将继续享受IDE和工具带来的好处,例如删除不赞成使用的代码结构的名称。

翻译自: https://www.javacodegeeks.com/2015/11/what-might-a-new-deprecated-look-like.html

deprecated

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/337083.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

轨道运营管理专业自荐书_轨道运营管理专业自荐信x

轨道运营管理专业自荐信尊敬的领导:您好!非常感谢您们在百忙之中审阅我的求职资料。这对一个即将步入社 会的学子来说是莫大的鼓舞。我是西安联合学院城市轨道运营管理专业的一名学生, 2011年 7 月即将步 入社会,心情是那么的激动…

让C语言源码可知自身函数的实际地址与大小

点击蓝字关注我们因公众号更改推送规则,请点“在看”并加“星标”第一时间获取精彩技术分享来源于网络,侵删事情的起因大概是这样……在很久很久以前,我最早用的是MASM(Win32ASM)写程序,从平台兼容性、开发…

java设计模式迭代器模式_迭代器设计模式示例

java设计模式迭代器模式本文是我们名为“ Java设计模式 ”的学院课程的一部分。 在本课程中,您将深入研究大量的设计模式,并了解如何在Java中实现和利用它们。 您将了解模式如此重要的原因,并了解何时以及如何应用模式中的每一个。 在这里查…

平衡二叉树 C语言代码实现

点击蓝字关注我们因公众号更改推送规则,请点“在看”并加“星标”第一时间获取精彩技术分享来源于网络,侵删1.什么是平衡二叉树平衡二叉树,我们也称【二叉平衡搜索树/AVL】,树中任何节点的两个子树的高度最大差别为1,巴拉巴拉。。…

api报错 javaee maven_maven test 换javaee6 无法加载spring的配置文件 ?报错-问答-阿里云开发者社区-阿里云...

maven 构建的springmvc项目,执行mvn test 时 如果是org.apache.openejbjavaee-api5.0-3那么执行test可以通过如果将version改为6.0-3 则报错, Failed to load ApplicationContextTest:RunWith(SpringJUnit4ClassRunner.class)ContextConfiguration(locations "classpath*…

研发项目wbs分解简单案例_做项目WBS(工作分解结构)

显示视图栏:右键左边灰色,选“视图栏”。预先设置:文件---》选项,可以设置日期等格式信息,比如可以把日期格式改成2009年1月28日 12:33, 把工期显示单位改成小时数,这样我们可以做更细的任务分解。新建日历…

hystrix熔断 简介_Hystrix简介–总结

hystrix熔断 简介这是其他两篇文章的后续文章– 动机 ,说明为什么在分布式系统中需要类似Hystrix的内容以及Hystrix的基本介绍 。 这将是我的Hystrix旅程的总结,其中包含各种属性的详细信息,这些属性可以进行调整以更改Hystrix的行为&#x…

UDP/TCP 包的大小限制知多少

点击蓝字关注我们因公众号更改推送规则,请点“在看”并加“星标”第一时间获取精彩技术分享来源于网络,侵删一、MTU 简述 - 分包后数据包最大长度1、定义Maximum Transmission Unit(最大可传输单元) 的缩写,它的单位是…

autocad2014 菜单栏 闪退_AutoCAD2014闪退的原因与处理办法 1打开就闪退怎样办

软件安装:装机软件必备包关于电脑装机必须的软件,比如windows office系列办公软件、网页浏览器、杀毒软件、安全防护软件、刻录软件、压缩软件、下载工具、多媒体播放软件、多媒体编辑软件、输入法、图片查看和处理软件、聊天沟通工具、系统工具与驱动补…

java ee的小程序_扩展Java EE应用程序的基础

java ee的小程序老实说,“可扩展性”是一个详尽的主题,并且通常没有被很好地理解。 通常,它被认为与高可用性相同。 我已经看到新手程序员和“经验丰富”的建筑师都建议将“ 群集 ”作为可伸缩性和HA的解决方案。 它实际上没有任何问题&#…

28 张图,一次性说清楚 TCP,速度

点击蓝字关注我们因公众号更改推送规则,请点“在看”并加“星标”第一时间获取精彩技术分享来源于网络,侵删做IT相关的工作,肯定都离不开网络,网络中最重要的协议是TCP。无论是实际工作还是笔试面试,你看哪里能少得了T…

晨风机器人怎么买奴隶_潮牌复刻和正品该怎么抉择???带你了解了解

今天带你们聊一聊潮牌复刻和正品,简单介绍一下我自己,在复刻圈子五年,我的原则从始至终就是质量放在第一位,之所以能走这么久也是这个原因。回归正题,接着往下看。无论是正品还是复刻,其实还要根据自己的能…

php cdi_本机CDI限定词:@Any和@Default

php cdi让我们看一下CDI中的开箱即用的限定词 CDI规范声明了三个限定符– Any, Default, New Any :将其视为无所不在的限定词。 它在那里,即使不是;-) Default :顾名思义,当没有其他限定符时&#xff0…

C语言字符串函数strcat | strcpy | strlen | strcmp的用法及原型

点击蓝字关注我们因公众号更改推送规则&#xff0c;请点“在看”并加“星标”第一时间获取精彩技术分享来源于网络&#xff0c;侵删strcat(str1,str2) 意为将字符串str2连接到字符串str1之后strcat用法如下#include <stdio.h> #include <string.h>int main () {cha…

crntos7启动php命令_CentOS7设置php-fpm开机自启动

php-fpm安装成功后并不会开机启动&#xff0c;如果是运行正常的程序在系统重启后出现502报错(502 Bad Gateway)&#xff0c;通常就是php-fpm没启动起来。0 先确定几个文件的位置&#xff0c;记录下来备用a php-fpmwhich php-fpm/usr/sbin/php-fpmb conf#几个可能的位置#/etc/ph…

java jpa 异步编程_异步处理时的JPA

java jpa 异步编程几年前&#xff0c;在Java世界中&#xff0c;几乎显而易见的是&#xff0c;每个“企业”类项目都需要JPA与数据库进行通信。 JPA是Joel Spolsky描述的“ 泄漏抽象 ”的完美示例。 刚开始时很棒而又容易&#xff0c;但是最后很难调整和限制。 对于许多参与数据…

C语言字符数组与字符串的使用详解

点击蓝字关注我们因公众号更改推送规则&#xff0c;请点“在看”并加“星标”第一时间获取精彩技术分享来源于网络&#xff0c;侵删正文1、字符数组的定义与初始化字符数组的初始化&#xff0c;最容易理解的方式就是逐个字符赋给数组中各元素。char str[10]{ I, ,a,m, ,‘h,a,p…

SRC挖洞网集合

阿里SRC https://security.alibaba.com/ 蚂蚁集团SRC https://security.alipay.com/ 阿里本地生活SRC https://asrc.alibaba.com/#/ 京东安全应急响应中心 https://security.jd.com/#/ 腾讯SRC https://security.tencent.com/ 美团安全应急响应中心 https://security.meit…

不能将紧实的字段 绑定到_代码整洁之道【笔记】

一、整洁代码A.混乱的代价1.有些团队在项目初期进展迅速&#xff0c;但有那么一两年的时间却慢去蜗行。对代码的每次修改都影响到其他两三处代码2.花时间保持代码整洁不但有关效率&#xff0c;还有关生存3.程序员遵从不了解混乱风险经理的意愿&#xff0c;也是不专业的做法4.Bj…

存根类 测试代码 java_测试双打:模拟,假人和存根

存根类 测试代码 java大多数班级都有合作者。 在进行单元测试时&#xff0c;您通常希望避免使用那些协作者的实际实现方式来避免测试的脆弱性和绑定/耦合&#xff0c;而应使用测试双打&#xff1a;模拟&#xff0c;存根和双打。 本文引用了有关该主题的两篇现有文章&#xff1…