[英]How to suppress deprecation warning on annotation argument
I compile javac 1.7.0_45 using the -Xlint
option, the following code causes a deprecation warning. 我使用
-Xlint
选项编译javac 1.7.0_45,以下代码会导致弃用警告。
@Deprecated
public class Bar {}
@SuppressWarnings("deprecation")
public class Foo {
@XmlElement(type = Bar.class)
Object something;
}
>> Warning: Bar in mavenproject1 has been deprecated
I would have expected the @SuppressWarnings
to prevent the warning message to be raised. 我本来希望
@SuppressWarnings
可以防止发出警告消息。
How to avoid this warning ? 如何避免这种警告?
I have a feeling this is a bug / spec ambiguity that hasn't been addressed. 我觉得这是一个错误/规范的模糊性,尚未解决。 If you search the bug database there are plenty of these, such as: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7117383
如果搜索错误数据库,则有很多这样的数据库 ,例如: http : //bugs.java.com/bugdatabase/view_bug.do?bug_id=7117383
A program element annotated @Deprecated is one that programmers are discouraged from using, typically because it is dangerous, or because a better alternative exists. 注释为@Deprecated的程序元素是不鼓励程序员使用的元素,通常是因为这样做很危险,或者因为存在更好的替代方法。 Compilers warn when a deprecated program element is used or overridden in non-deprecated code.
当在不推荐使用的代码中使用或覆盖不推荐使用的程序元素时,编译器会发出警告。
http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Deprecated.html http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Deprecated.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.