Is Anyone knows if the class with @Deprecated
annotation means that all methods and fields automatically will be deprecated..?
From JLS 9.6.3.6. @Deprecated
At lease eclipse is not showing methods as Deprecated
for Deprecated class.
No. If you do
@Deprecated
class Old {
public void foo () {}
}
the when you'll reference that class:
new
Old().foo()
only
Old
will be marked as deprecated.
If say I have annotated the class VO
with @Deprecated
:
@Deprecated
class VO {
private String name ;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
Then :
VOv = new VO(); // warning here
v.getName(); // no warning
It means the class is deprecated. Hence the use of that type will show warning.
Well, the spec says this:
A Java compiler must produce a deprecation warning when a type [..] whose declaration is annotated with the annotation @Deprecated is used (i.e. overridden, invoked, or referenced by name), [..]
So strictly speaking calling a method on an object of which the type is deprecated is not required to produce a warning (since "overridden" and "invoked" can only reference methods or constructors and the class is not referenced by name). Declaring that object, however must provide a warning.
However, nothing says that the compiler isn't allowed to provide more warnings. And in my opinion it is reasonable to assume that all methods of a deprecated class should be considered deprecated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With