@SuppressWarnings的使用、作用、用法

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值