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"}).呵呵,成了.
???????
??????? 好久没用接触过标注了,快忘了. 现在记下来.
@SuppressWarnings("serial").
2 楼 JohnnyJian 2008-06-24 @SuppressWarnings({"deprecation","unchecked"}) 3 楼 tianxinet 2008-06-25 Direct Manager/Leader always tough ;-)
他的Picky本次客观上改进了结果,总的来说,PICKY is not very good - not for all situation 4 楼 huang_yong 2010-06-05 可以使用 @SuppressWarnings("all") 来去掉所有的警告 5 楼 rmn190 2010-06-07 huang_yong 写道可以使用 @SuppressWarnings("all") 来去掉所有的警告
多谢!