@SuppressWarnings的使用、作用、用法
来源:互联网 发布:网络k歌动圈麦克风推荐 编辑:程序博客网 时间:2024/06/07 09:12
在Java编译过程中会出现很多警告,有很多是安全的,但是每次编译有很多警告影响我们对error的过滤和修改,我们可以在代码中加上
@SuppressWarnings(“XXXX”) 来解决
例如:@SuppressWarnings("deprecation")表示不显示使用了不赞成使用的类或方法时的警告;
(“xxx”)里面的参数有如下几种:
- all to suppress all warnings
- boxing to suppress warnings relative to boxing/unboxing operations
- cast to suppress warnings relative to cast operations
- dep-ann to suppress warnings relative to deprecated annotation
- deprecation to suppress warnings relative to deprecation
- fallthrough to suppress warnings relative to missing breaks in switch statements
- finally to suppress warnings relative to finally block that don’t return
- hiding to suppress warnings relative to locals that hide variable
- incomplete-switch to suppress warnings relative to missing entries in a switch statement (enum case)
- nls to suppress warnings relative to non-nls string literals
- null to suppress warnings relative to null analysis
- rawtypes to suppress warnings relative to un-specific types when using generics on class params
- restriction to suppress warnings relative to usage of discouraged or forbidden references
- serial to suppress warnings relative to missing serialVersionUID field for a serializable class
- static-access to suppress warnings relative to incorrect static access
- synthetic-access to suppress warnings relative to unoptimized access from inner classes
- unchecked to suppress warnings relative to unchecked operations
- unqualified-field-access to suppress warnings relative to field access unqualified
- unused to suppress warnings relative to unused code
- 例如:
@SuppressWarnings("serial")@WebServlet(name="ajax",urlPatterns="/servlet/ajax")public class ajax extends HttpServlet { public void init() throws ServletException {} protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { doActionPage(request, response); } protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { doActionPage(request, response); } public static Object execMethod(String classNameAndMethod, String inputVal) throws Exception{ int lastPoint = Util.NVLL(classNameAndMethod).lastIndexOf("."); inputVal = Util.NVLL(inputVal); if(lastPoint < 0) return inputVal; try { String className = classNameAndMethod.substring(0, lastPoint); String methodName = classNameAndMethod.substring(lastPoint+1); int firstPa = methodName.indexOf("("); if(firstPa >0) methodName = methodName.substring(0, firstPa); Class clazzxxx = Class.forName(className); if(inputVal.length() < 1) { java.lang.reflect.Method m = clazzxxx.getDeclaredMethod(methodName, new Class[] {}); return m.invoke((Object) null, new Object[0]); } else { java.lang.reflect.Method m = clazzxxx.getDeclaredMethod(methodName, new Class[] {String.class}); return m.invoke(null, inputVal); } } catch (Exception r) { Log.log("ERROR: ajax:" + classNameAndMethod + ", input value=" + inputVal); r.printStackTrace(); throw r; }...}
阅读全文
0 0
- @SuppressWarnings的使用、作用、用法
- @SuppressWarnings的使用、作用、用法
- @SuppressWarnings的使用、作用、用法
- @SuppressWarnings的使用、作用、用法
- @SuppressWarnings的使用、作用、用法
- @SuppressWarnings的使用、作用、用法
- @SuppressWarnings的使用、作用、用法
- SuppressWarnings的使用、作用、用法
- @SuppressWarnings的使用、作用、用法
- @SuppressWarnings的使用、作用、用法
- @SuppressWarnings的使用、作用、用法
- @SuppressWarnings的使用、作用、用法
- @SuppressWarnings的使用、作用、用法
- @SuppressWarnings的使用、作用、用法
- @SuppressWarnings的使用、作用、用法
- @SuppressWarnings("serial")的作用
- @SuppressWarnings注解的作用
- @SuppressWarnings注解的用法
- C-1
- 九度 题目1342:寻找最长合法括号序列II(25分)
- 搜索 P
- web前端学习
- Fire! UVA
- @SuppressWarnings的使用、作用、用法
- C++上机实验6——数组合并
- Viewport 手机屏幕尺寸--webApp学习(一)
- C++中的 & 与 &&
- Ubuntu安装docker
- FPGA与LVDS信号兼容性分析方法
- HDU4883TIANKENG’s restaurant
- 保留的 IPv4 地址
- C++作业5