Will JVM issue warning during runtime for using @deprecated codes?
If it doesn't, can i make it warn for using @deprecated codes?
Will JVM issue warning during runtime for using @deprecated codes?
No.
If it doesn't, can i make it warn for using @deprecated codes?
Not any way that I know of.
OTOH it is possible to find out in code, at runtime, if a particular member is deprecated:
import java.awt.Panel;
import java.lang.reflect.Method;
import java.lang.annotation.Annotation;
class TestAnnotations {
@Deprecated
public Object getStuff() {
return null;
}
public static void showAnnotations(
Object obj,
String methodName) throws Exception {
Class cls = obj.getClass();
Method m = cls.getMethod(methodName);
System.out.println(m);
Annotation[] as = m.getDeclaredAnnotations();
for (Annotation a : as) {
System.out.println(a);
}
}
public static void main(String[] args) throws Exception {
Panel p = new Panel();
showAnnotations(p, "show");
TestAnnotations ta = new TestAnnotations();
showAnnotations(ta, "getStuff");
}
}
public void java.awt.Component.show()
@java.lang.Deprecated()
public java.lang.Object TestAnnotations.getStuff()
@java.lang.Deprecated()
Press any key to continue . . .
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