java标记过期方法

2019-11-09 19:16:35

ava注解:@Deprecated(不建议使用的,废弃的), @SuppressWarnings(忽略警告,达到抑制编译器产生警告的目的)

@Deprecated可以修饰类、方法、变量,在java源码中被@Deprecated修饰的类、方法、变量等表示不建议使用的,可能会出现错误的,可能以后会被删除的类、方法等,如果现在使用,则在以后使用了这些类、方法的程序在更新新的JDK、jar包等就会出错,不再提供支持。     个人程序中的类、方法、变量用@Deprecated修饰同样是不希望自己和别人在以后的时间再次使用此类、方法。  当编译器编译时遇到了使用@Deprecated修饰的类、方法、变量时会提示相应的警告信息。

@SuppressWarnings 可以达到抑制编译器编译时产生警告的目的,但是很不建议使用@SuppressWarnings注解,使用此注解,编码人员看不到编译时编译器提示的相应的警告,不能选择更好、更新的类、方法或者不能编写更规范的编码。同时后期更新JDK、jar包等源码时,使用@SuppressWarnings注解的代码可能受新的JDK、jar包代码的支持,出现错误,仍然需要修改。

可以看成@Deprecated注解和@SuppressWarnings注解是成对出现的。

通过@SuppressWarnings的源码可知,其注解目标为类、字段、函数、函数入参、构造函数和函数的局部变量。而家建议注解应声明在最接近警告发生的位置

    /** 
	* @Description: 编码时我们总会发现如下变量未被使用的警告提示,
	* 上述代码编译通过且可以运行,但每行前面的“感叹号”就严重阻碍了我们判断该行是否设置的断点了。
	* 这时我们可以在方法前添加 @SuppressWarnings("unchecked") 去除这些“感叹号”。
	*/
	public String convertXmlToSendMethods(Document document){
		//发布方式(1到多个)
		List<Element> methodName = document.selectNodes("/alert/code/method/methodName");
		List<Element> message = document.selectNodes("/alert/code/method/message");
		List<Element> audienceGrp = document.selectNodes("/alert/code/method/audienceGrp");
		List<Element> audenceprt = document.selectNodes("/alert/code/method/audenceprt");
		//处理‘发布方式’复数
		int methodNameSize = 0;
		if (null!=methodName && methodName.size()>0) {
			methodNameSize = methodName.size();
		}
		JSONArray jsonArraySendMethods = new JSONArray();
		for (int i = 0; i < methodNameSize; i++) {
			JSONObject json = new JSONObject();
			json.put("methodName", methodName.get(i).getTextTrim());
			json.put("message", message.get(i).getTextTrim());
			json.put("audienceGrp", audienceGrp.get(i).getTextTrim());
			json.put("audenceprt", audenceprt.get(i).getTextTrim());
			jsonArraySendMethods.put(json);
		}
		return jsonArraySendMethods.toString();
	}


@SuppressWarings注解 详解

    /** 
	* @Description:示例1——抑制单类型的警告: 
	*/
	@SuppressWarnings("unchecked")
	public void addItems(String item){
	  @SuppressWarnings("rawtypes")
	   List items = new ArrayList();
	   items.add(item);
	}
	
	/** 
	* @Description: 示例2——抑制多类型的警告: 
	*/
	@SuppressWarnings(value={"unchecked", "rawtypes"})
	public void addItems(String item){
	   List items = new ArrayList();
	   items.add(item);
	}
	
	/** 
	* @Description:示例3——抑制所有类型的警告:
	*/
	@SuppressWarnings("all")
	public void addItems(String item){
	   List items = new ArrayList();
	   items.add(item);
	}


抑制警告的关键字


关键字 用途

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 o 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


  • 2020-02-22 17:35:14

    使用tweenjs写一个发牌的demo

    移动端h5的三大抽奖方式:转盘,老虎机,翻纸牌。 前两样demo比较多,用户也审美疲劳了。这次微信公众号要抽奖,于是调研了下翻纸牌。

  • 2020-02-22 17:45:43

    tweenjs简单快速学习

    tweenjs 是使用 JavaScript 中的一个简单的补间动画库,支持数字、对象的属性和 CSS 样式属性的赋值。 tweenjs 以平滑的方式修改元素的属性值,需要传递给 tween 要修改的值、动画结束时的最终值和动画花费时间(duration),之后 tween 引擎就可以计算从开始动画点到结束动画点之间值,从而产生平滑的动画效果。

  • 2020-02-22 17:47:12

    easeJs入门学习教程

    createjs中包含以下四个部分: EaselJS:用于 Sprites、动画、向量和位图的绘制,创建 HTML5 Canvas 上的交互体验(包含多点触控) TweenJS:用于做动画效果 SoundJS:音频播放引擎 PreloadJS:网站资源预加载

  • 2020-02-22 17:54:59

    最新FullCalendar中文文档

    Fullcalendar是一款用来管理日程安排、工作计划的日历工具,它功能非常强大而且非常实用。而目前网络上没有很好的中文文档,为了更好的和大家分享Fullcalendar的相关使用,即日起计划将Fullcalendar的英文文档翻译成中文版。

  • 2020-02-22 17:57:05

    nuxtjs支持api接口,serverMiddleware

    Who can’t relate to this: You’ve built a small portfolio page for someone, maybe a company, a friend or yourself. And the only API endpoint you’d need is one for a form. What now? Scaffolding a new service just for this one endpoint?

  • 2020-02-22 17:59:34

    FullCalendar插件的基本使用带详细配置翻译

    前段时间,一直在开发考勤系统,当时为满足设计的需求,选了好几个插件,最后决定采用Fullcanlendar的插件。感觉这个插件可以满足现阶段的功能开发需求

  • 2020-02-22 18:03:10

    Vue组件中使用Sass或者Less全局变量

    本文以Sass做案例,Less的参考,基本配置大同小异。 假如我们有一个Sass的全局变量common.scss文件,路径 ../style/common.scss 代码如下: