简体   繁体   中英

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.

@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.

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

A program element annotated @Deprecated is one that programmers are discouraged from using, typically because it is dangerous, or because a better alternative exists. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM