How to Use @Deprecated Annotation in Java


In this example, we will learn how to use @Deprecated annotation to inform the compiler to generate a warning whenever a program uses a method, class, or field with the @Deprecated annotation in Java.

Source Code

package com.beginner.examples;


public class DeprecatedExample {
    
    @Deprecated
    public void test(){
        System.out.println("It is deprecated.");
    }
     
    public static void main(String a[]){
         
        DeprecatedExample d = new DeprecatedExample();
        // call the deprecated method
        d.test();
    }
}

Output:

It is deprecated.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments