☰
The main goal of this JEP(JDK Enhancement Proposal) is to revamp the @Deprecated annotation, and provide tools to strengthen the API life cycle. It intends to provide better information about the status and intended disposition of APIs in the specification
Deprecation is a notification to library consumers that they should migrate code from a deprecated API. Deprecation is a technique to communicate information about the life cycle of an API: to encourage applications to migrate away from the API, to discourage applications from forming new dependencies on the API, and to inform developers of the risks of continuing dependence upon the API.
APIs have been deprecated for widely varying reasons, such as:
Java offers two mechanisms to express deprecation:
@deprecated Javadoc tag, introduced in JDK 1.1,
@Deprecated annotation, introduced in Java SE 5.A program element annotated @Deprecated is one that programmers are discouraged from using, typically because it is dangerous, or because a better alternative exists. Compilers warn when a deprecated program element is used or overridden in non-deprecated code.
However,very few deprecated APIs were actually removed, leading some people to believe that nothing would ever be removed. On the other hand, other people believed that everything that was deprecated might eventually be removed, which was never the intent either. This resulted in an unclear message being delivered to developers about the meaning of @Deprecated.
Starting with JDK 9, APIs may be marked as deprecated for removal. This indicates that the API is eligible to be removed in the next release of the JDK platform. If your application or library consumes any of these APIs, then you should make a plan to migrate from them soon.
To indicate deprecation, precede the module, class, method, or member declaration with @Deprecated. The annotation contains these elements:
since
The value of this element indicates the version in which the annotated program element was first deprecated.
@Deprecated(since="<version>")
forRemoval
A value of true indicates intent to remove the annotated program element in a future version. A value of false indicates that use of the annotated program element is discouraged, but at the time the program element was annotated, there was no specific intent to remove it.
@Deprecated(forRemoval=<boolean>)
For example:
@Deprecated(since="9", forRemoval=true)
Indicates that the API is deprecated in JDK9 and beyond and is eligible to be removed in a future release of the JDK platform.