Annotation(注解)
来源:互联网 发布:a星算法优化 编辑:程序博客网 时间:2024/06/03 19:27
1.准确覆写@Override
如果准确控制覆写要求,使用@Override,如果覆写不正确,则它提示错误
package com.wjx.sayHello;class Persons{@Override//The method tostring() of type Persons must override or implement a supertype method//如果写了@Override没有覆写toString()会提示上述问题public String tostring(){return "hello";}}public class TestDemo {public static void main(String[] args){System.out.println(new Persons());}}
2 .声明过期处理@Deprecated
一些程序类再新版本不希望继续使用,但是在老版本里面还得继续使用,不能删除,此时我们声明注解@Deprecated来表示,声明过的方法或者类不建议使用,但是使用不会报错。
package com.wjx.sayHello;class Persons{@Deprecatedpublic Persons(){}public Persons(String name){}@Deprecatedpublic void fun(){}}public class TestDemo {public static void main(String[] args){Persons p=new Persons();Persons p1=new Persons("李四");p.fun();}}3. 压制警告@
当调用某些方法,定义方法对象等操作时候,程序出现警告时候的时候,你不想让开发工具提示警告可以使用压制警告来避免提示警告
package com.wjx.sayHello;class Persons<T>{@Deprecatedpublic Persons(){}public Persons(String name){}@Deprecatedpublic void fun(){}}public class TestDemo {@SuppressWarnings({ "rawtypes", "unused" })public static void main(String[] args){//p使用Object接受对象,由于persons为泛型 没声明对象类型会出现警告Persons p=new Persons();//p1为使用,会出现警告Persons p1=new Persons("李四");p.fun();}}
阅读全文
0 0
- 注解(Annotation)--注解处理器
- 注解(Annotation)自定义注解
- 注解(Annotation)--注解处理器
- 注解(Annotation)--注解处理器
- JAVA 注解(annotation)
- 注解(Annotation)
- Annotation(注解)是什么?
- java 注解(Annotation)
- 注解(Annotation)
- 30、注解(Annotation)
- java 注解(annotation)
- JAVA 注解(Annotation)
- Java 注解(annotation)
- 注解(Annotation)
- Annotation(@注解)
- javaEE-Annotation(注解)
- Annotation注解 (一)
- 自定义Annotation(注解)
- 一位资深程序员大牛给予Java初学者的学习路线建议
- 外观模式
- sql处理小技巧
- 深入了解MyBatis参数
- Java设计模式之迭代器模式
- Annotation(注解)
- 有关Lucene的问题(3): 向量空间模型与Lucene的打分机制
- 网站被降权或site首页不见的处理方法
- Pots POJ
- elasticsearch-5.6.0及head插件安装
- 学习Tutorial--catlikecoding
- ScrollView自动布局的实现方式
- LIVE555再学习 -- Linux 下编译
- 基于S3C2440的嵌入式Linux驱动——Framebuffer子系统解读