Home > Java > javaTutorial > What properties does the @Deprecated annotation add in Java 9?

What properties does the @Deprecated annotation add in Java 9?

PHPz
Release: 2023-08-28 15:49:02
forward
1297 people have browsed it

在Java 9中,@Deprecated注解添加了哪些属性?

Two new parameters or properties have been added in the @Deprecated annotation in Java 9. These parameters are Since and forRemoval, these two parameters are optional when we cannot specify them, with default values.

Because

this string parameter specifies a deprecated version of the API. The default value for this element is emptystring.

Syntax

<strong>@Deprecated(since="<version>")</strong>
Copy after login

forRemoval

This Boolean parameter specifies whether the API is intended to be removed in a future release. When we cannot specify, the default value is false.

Syntax

<strong>@Deprecated(forRemoval=<boolean>)</strong>
Copy after login

Example

public class DeprecatedAnnotationTest {
   public static void main(String[] args) {
      DeprecatedAnnotationTest test = new DeprecatedAnnotationTest();
      test.method1();
      test.method2();
   }
<strong>   @Deprecated(since="7.0")</strong>
   public void method1() {
      System.out.println("@Deprecated(since=\"7.0\")");
   }
<strong>   @Deprecated(since="5.0", forRemoval=true)</strong>
   public void method2() {
      System.out.println("@Deprecated(since=\"5.0\", forRemoval=true)");
   }
}
Copy after login

Output

<strong>@Deprecated(since="7.0")
@Deprecated(since="5.0", forRemoval=true)</strong>
Copy after login

The above is the detailed content of What properties does the @Deprecated annotation add in Java 9?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template