概述
Annotations (Metadata) – This language feature lets you avoid writing boilerplate code under many circumstances by enabling tools to generate it from annotations in the source code. This leads to a "declarative" programming style where the programmer says what should be done and tools emit the code to do it. Also it eliminates the need for maintaining "side files" that must be kept up to date with changes in source files. Instead the information can be maintained inthe source file.
Annotation,即注解
所谓注解,顾名思义,就是为Java的类或者方法在添加一个带有提示功能的注释,与注释不同的是,它相当于一个接口,这个接口中定义了一些具有提示意义的方法,所以,注解的作用就是提示功能,且不影响原来代码的语法
我们也可以看到,注解的标识符为@interface,也就代表了,,它是一个与接口类似的类,它的使用范围和访问性都与接口相似
标准的注解与使用
Java在lang包中提供的标准注解有以下三个
注释类型DeprecatedOverrideSuppressWarnings
Deprcated代表被注释的元素已经过时
Override代表被注释的元素是复写了父类的实现
SuppressWarning代表被注释的元素取消编译器警告
下面就是这个三个注解的应用
SimpleAnnotationTest { 2: 3:/** 4: * @param args 5: */ 6:@SuppressWarnings("Deprecation")//忽略编译器对show方法的过时警告main(String[] args) { 8:// TODO Auto-generated method stub 9: 10:show(); 11:} 12: 13:@Deprecated//注明此方法已过时show(){ 15:System.out.println("hello"); 16:} 17: 18:@Override//复写了父类的toString方法 19:public String toString() { 20:// TODO Auto-generated method stub.toString(); 22:} 23: }你必须百分之百的把自己推销给自己。