")forRemoval This boolean parameter specifies whether the API is intended to be removed in a future version. When we cannot specify it, the default value is false. Syntax@Deprecated(forRemoval= ")forRemoval This boolean parameter specifies whether the API is intended to be removed in a future version. When we cannot specify it, the default value is false. Syntax@Deprecated(forRemoval=

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

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

PHPz
PHPzforward
2023-08-28 15:49:021212browse

在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>

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>

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)");
   }
}

Output

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

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete