Java - Deprecated Annotation Type

Introduction

The Deprecated annotation type is a marker annotation type.

You can use it to mark deprecated code.

When you compile the code which is using the deprecated code, it will generate a compiler note stating that you are using the deprecated code.

Example

The DeprecatedTest class in the following code is marked with Deprecated annotation.

@Deprecated
class DeprecatedTest {
}

When you compile the Test class, it will generate a compiler note stating that the deprecated DeprecatedTest class should not be used.

class Test {
   public static void main(String[] args) {
        DeprecatedTest dt; // Generates a compile-time note
   }
}