简体   繁体   English

如何取消对注释参数的弃用警告

[英]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.

相关问题 自定义注释以禁止特定的FindBugs警告 - Custom annotation to suppress a specific FindBugs warning Java:抑制 NullPointerException 警告的方法注释 - Java: Method annotation to suppress NullPointerException warning 如何解决类型安全警告从集合到列表的未经检查的强制转换 <File> 没有抑制注释的Java 6 - How to address Type safety warning Unchecked cast from Collection to List<File> Java 6 without suppress annotation 如何抑制警告“无法解析方法”,因为您使用注释生成方法? - How to suppress warning 'cannot resolve method' because you generate the method using annotation? 如何抑制未经检查的课堂警告 - How to suppress unchecked class warning 如何在 `var` 关键字上抑制此警告? - how to suppress this warning on the `var` keyword? 如何删除休眠弃用警告消息 - How to remove Hibernate deprecation warning message 我应该使用问号类型参数还是禁止原始类型警告? - Should I use question mark type argument or suppress rawtypes warning? 如何在java中抑制空指针访问警告? - How to suppress null pointer access warning in java? 如何使用泛型而不是声明来抑制未检查的类型转换警告? - How to suppress unchecked typecast warning with generics not at declaration?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM