about @SuppressWarnings.

about  @SuppressWarnings.

        项目组来了个很Picky的头,看到Eclipse里有大量的Warning小发了下脾气后,让用@SuppressWarnings这个标注来把Warning去掉.
       
        为了去掉由于泛型的Warning,我们用了@SuppressWarnings("unchecked"),为了去掉那些由于deprecation而引起的Warning,用了@SuppressWarnings("deprecation").但一个类中既有unchecked又有deprecation时,怎么办?于是用了一个很权宜之计:在类声明那用@SuppressWarnings("deprecation"),而在相应的方法声明里用@SuppressWarnings("unchecked").

       用了效果当然也达到了,可就想问在一个单独的@SuppressWarnings里既去掉deprecation又去掉unchecked呢?觉得应该可以达到的.于是就用下面的方式来试.
        1,@SuppressWarnings("deprecation","unchecked"),不行,Eclipse报错.
         2,@SuppressWarnings("deprecation,unchecked"),不行,还是报错.
         3,看@SuppressWarnings的源码,只有一个String[]类型的value.就想用@SuppressWarnings(new String[]{"deprecation","unchecked"}),还是不行,报错.
         4, Google了下后,发现了这个@SuppressWarnings(value={"deprecation"}),于是就想起来了@SuppressWarnings(value={"deprecation","unchecked"}).呵呵,成了.
       
        好久没用接触过标注了,快忘了. 现在记下来.


posted @ 2012-03-06 10:17  fedorayang  阅读(95)  评论(0编辑  收藏  举报