Java Annotation
来源:互联网 发布:windows平板模式模拟器 编辑:程序博客网 时间:2024/05/18 03:02
package annotation;import java.lang.annotation.ElementType;import java.lang.annotation.Inherited;import java.lang.annotation.Retention;import java.lang.annotation.RetentionPolicy;import java.lang.annotation.Target;import java.lang.reflect.Method;//取值(ElementType)有://1.CONSTRUCTOR:用于描述构造器//2.FIELD:用于描述域//3.LOCAL_VARIABLE:用于描述局部变量//4.METHOD:用于描述方法//5.PACKAGE:用于描述包//6.PARAMETER:用于描述参数//7.TYPE:用于描述类、接口(包括注解类型) 或enum声明 //取值(RetentionPoicy)有://1.SOURCE:在源文件中有效(即源文件保留)//2.CLASS:在class文件中有效(即class保留)//3.RUNTIME:在运行时有效(即运行时保留)@Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) //@Inherited@interface Test{ public int id() default 1; public String value() default "hello world";}class People{ @Test(id=2) public void fun(){}}public class Main { public static void main(String[] args) { Method methods[]=People.class.getDeclaredMethods(); for(int i=0;i<methods.length;i++){ Test test=methods[i].getAnnotation(Test.class); if(test!=null){ System.out.println(test.id()+" "+test.value()); } } }}
0 0
- JAVA Annotation & 自定义Annotation
- java Annotation Annotation elements
- Java Annotation
- Java Annotation
- Java Annotation
- Java Annotation
- Java Annotation
- java annotation
- Java Annotation
- Java Annotation
- Java Annotation
- Java Annotation
- JAVA [ Annotation]
- Java Annotation
- java annotation
- Java annotation
- Java Annotation
- JAVA --Annotation
- mqtt bug
- 获取 webView 的 userAgent 并修改
- const的位置
- 蓝桥杯--2013--马虎的算式(暴力)
- eclipse sdk下载不下来
- Java Annotation
- 迷宫最短路径长度bfs
- 网络时间同步
- HashMap的containskey源码分析
- JVM调优应用实战
- 三点顺序(三个点的顺序)
- 关东升的《从零开始学Swift》3月9日已经上架
- switch()允许的数据类型
- 检测网路状态 Reachability