Yishu Fang
Yishu Fang

Reputation: 9958

Why @Deprecated does not work here?

I have a java program like this:

public class Demo {
        /**
         * @deprecated use of func is discouraged.
         */
        @Deprecated
        static void func() {}

        public static void main(String[] args){
                func();
        }
}

Why when I try to compile it using javac, it does not give me any warnings.

Upvotes: 2

Views: 286

Answers (1)

SJuan76
SJuan76

Reputation: 24855

http://docs.oracle.com/javase/7/docs/technotes/guides/javadoc/deprecation/deprecation.html

It says

Using the annotation causes the Java compiler to generate warnings when the deprecated class, method, or field is used. The compiler suppresses deprecation warnings if a deprecated compilation unit uses a deprecated class, method, or field. This enables you to build legacy APIs without generating warnings.

If you compile your class, you see that you are using a deprecated method. The issue is when you compile a class that uses a deprecated method.

Upvotes: 10

Related Questions