No compilation warning with @Deprecated annotation?
According to Java tutorial on Oracle, if deprecated method marked with @Deprecated annotation is used, compiler should be giving warning on compilation. But with following code sample, I am not getting any warning in the console.
Java version used: 1.8.0_112
Please let me know what could be missing here. Thanks.
public class PreDefinedAnnotationTypesTest {
/**
* This method is deprecated.
* @deprecated
*/
@Deprecated
public void m1(){
}
public static void main(String[] args) {
PreDefinedAnnotationTypesTest obj = new PreDefinedAnnotationTypesTest();
obj.m1();
}
}
From docs
The compiler suppresses deprecation warnings if a deprecated item is used within an entity which itself is deprecated or is used within the same outermost class
or is used in an entity that is annotated to suppress the warning.
so your function is being used within the same class in which it is declared simply try to use in some other class.
In the below image the wontShowWarning
function will not generate any warning although show()
funtion will, which is from another class.
The API design can have different rules for itself because it is presumed that the outermost classes will be modified according to new design so this is just a indication to other classes
For Compiling and running your Java program using Command Prompt:
javac -Xlint className.java
Link to screenshot: https://i.stack.imgur.com/fwVjQ.png
链接地址: http://www.djcxy.com/p/47292.html上一篇: 谷歌地图