Java注解Annotation

来源:互联网 发布:炒股训练软件 知乎 编辑:程序博客网 时间:2024/06/03 16:30
  • 简单的实例
//定义了一个简单的注解,具有方法 say();@Target(ElementType.TYPE)@Retention(RUNTIME)public @interface HelloAnnotation {    String say() default "Hi";//不能够有函数体}

简单的调用

//使用注解@HelloAnnotation(say = "Do it!")public class Main {    public static void main(String[] args) {        //获取注解        HelloAnnotation annotation = Main.class.getAnnotation(HelloAnnotation.class);//获取Main类上的注解对象        System.out.println(annotation.say());//调用注解对象的say方法,并打印到控制台    }}
  • 注解对象实际是动态代理对象

这里写图片描述

http://blog.csdn.net/lylwo317/article/details/52163304#comments

0 0