济南房地产网站建设,如何建设自己的网站,建网站选号域名,wordpress多个页面主题deprecatedJDK增强建议 #xff08;JEP#xff09;277#xff08;“ 增强的弃用 ”#xff09;建议“重新定义弃用注释#xff0c;并提供加强功能生命周期尾端的工具。” 当前 java.lang.Deprecated的一些限制使我困扰了一段时间。 我特别希望能够使用Deprecated提供文本JEP277“ 增强的弃用 ”建议“重新定义弃用注释并提供加强功能生命周期尾端的工具。” 当前 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 Javadocs 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 thats 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 APIs 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},since1.5, anticipatedRemoval1.9,replacementdustin.examples.annotations.demo.OtherClass)
public class DeprecatedClass
{final DateFormat dateFormat new SimpleDateFormat(yyyy-MM-ddTHH:mm:ss.SSSZ);dustin.examples.annotations.Deprecated(value{DANGEROUS}, since1.0,replacementjava.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.htmldeprecated