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"}).呵呵,成了.
好久没用接触过标注了,快忘了. 现在记下来.
分享到:
相关推荐
J2SE 提供的最后一个批注是 @SuppressWarnings。该批注的作用是给编译器一条指令,告诉它对被批注的代码元素内部的某些警告保持静默。 一点背景:J2SE 5.0 为 Java 语言增加了几个新的特性,并且和它们一起增加了...
关于@SuppressWarnings("uncheck ")
:java.lang.SuppressWarnings是J2SE 5.0中标准的Annotation之一。可以标注在类、字段、方法、参数、构造方法,以及局部变量上。
@SuppressWarnings("unused") private List pageList;// 存放分页中5页信息 @SuppressWarnings("unused") private boolean isFirstPage;// 是否为第一页 @SuppressWarnings("unused") private boolean ...
二、JDK中预定义的一些注解1.@Override2.@Deprecated3.@SuppressWarnings4.@SafeVarargs5.@FunctionalInterface三、自定义注解1.格式2.本质3.属性4.元注解(JDK的元Annotation)4.1.@Target4.2.@Retention4.3.@...
@SuppressWarnings("unchecked") public List getBookcase(); public Bookcase getBookcaseById(Long id); public boolean validateByName(String name); public int allRowCount(); @...
suppress-warnings.zip,@suppressWarnings注释的常量@suppressWarnings注释的常量
1. 注解的理解 2. 注解的使用示例 3. 如何自定义注解:参照@SuppressWarnings定义 4. 元注解 :对现有的注解进行解释说明的注解 5.
@SuppressWarnings("static-access") public FontFrame(MyNotepad myNotepad){ @SuppressWarnings("unused") int i = this.showConfirmDialog(myNotepad, createJPanel(), "字体", JOptionPane.OK_CANCEL_...
@SuppressWarnings({ "rawtypes", "unchecked" }) public void exportAndDownload(String templateFile, List<HashMap> datas) { try { filename = UUID.randomUUID() + templateFile; // FacesContext ...
@SuppressWarnings("unused") private boolean isFirstPage;//是否为第一页 @SuppressWarnings("unused") private boolean isLastPage;//是否为最后一页 @SuppressWarnings("unused") private boolean has...
@SuppressWarnings("serial") public class testCalculator extends Frame { GridLayout g1; Button b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15; Panel p1,p2; Double x,y; JTextField tf1 = ...
@SuppressWarnings("serial") class ERS_Block extends Frame { public static boolean isPlay=false; public static int level=1,score=0; public static TextField scoreField,levelField; public static ...
@SuppressWarnings("unchecked") public Map queryForMap(String sql_name, Object parameterObject, String keyProp,String valueProp) { Map map = null; try { map = sqlMap.queryForMap(sql_name, ...
@SuppressWarnings("unchecked") public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { //获取站点 CmsSite ...
@SuppressWarnings("rawtypes") Map map = new HashMap(); //设置二维码的级别 map.put(EncodeHintType.ERROR_CORRECTION,ErrorCorrectionLevel.M); //设置二维码中文本的编码格式 map.put(EncodeHintType....
@SuppressWarnings("deprecation") public static void main(String[] s) throws IOException{ try { URL url = new URL("http://www.kum.net.cn"); DataInputStream in = new DataInputStream(url.open...
java中的SuppressWarnings(xxx).doc
suppressWarnings的注解参数解释
java SuppressWarningsjava SuppressWarningsjava SuppressWarnings