A class with @Deprecated annotation means that all methods and fields will automatically expire

Does anyone know if a class with @Deprecated annotation means that all methods and fields will automatically be deprecated ..?

From JLS 9.6.3.6. @Deprecated

In rental mode, eclipse does not show methods as Deprecated for the Deprecated class.

+4
source share
3 answers

No. If you do

 @Deprecated class Old { public void foo () {} } 

when you will reference this class:

new Old (). foo ()

only

Old

will be marked as deprecated.

+4
source

If, say, I annotated the VO class using @Deprecated :

 @Deprecated class VO { private String name ; public void setName(String name) { this.name = name; } public String getName() { return name; } } 

Then:

VO v = new VO (); // warning here

 v.getName(); // no warning 

This means that the class is out of date. Therefore, using this type will show a warning.

+2
source

Well, the spec says the following:

The Java compiler should issue an obsolescence warning when the type [..] is used, the declaration of which is annotated with the @Deprecated annotation (that is, it is redefined, called, or called by name), [..]

So strictly speaking, calling a method on an object for which the type is deprecated is not required to create a warning (since "overridden" and "called" can only refer to methods or constructors, and the class does not refer to the name). The declaration of this object, however, should provide a warning.

However, nothing suggests that the compiler is not allowed to provide more warnings. And, in my opinion, it is reasonable to assume that all methods of an obsolete class should be considered obsolete.

+1
source

Source: https://habr.com/ru/post/1491114/


All Articles