Which attributes have added to @Deprecated annotation in Java 9?


There are two new parameters or attributes added to @Deprecated annotation in Java 9. Those parameters are Since and forRemoval, both of these two parameters are optional with a default value when we can't specify it.

Since

This string parameter specifies the version in which the API became deprecated. The default value of this element is an empty string.

Syntax

@Deprecated(since="<version>")

forRemoval

This boolean parameter specifies whether the API is intended to be removed in a future release or not. The default value is false when we can't specify it.

Syntax

@Deprecated(forRemoval=<boolean>)

Example

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

Output

@Deprecated(since="7.0")
@Deprecated(since="5.0", forRemoval=true)

raja
raja

e

Updated on: 21-Feb-2020

485 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements