首页 > 其他 > 详细

Annotation

时间:2018-11-30 00:05:33      阅读:232      评论:0      收藏:0      [点我收藏+]

Annotation

  概念:注解

原理

  是一种接口,通过反射机制中的相关API来访问annotation信息

常见的标准Annotation

@Override   方法重写

@Deprecated  表示过期的东西警告

@SuppressWarnnings    取消显示指定的警告

 

自定义Annotation

访问修饰符  @interface Annotation名称{

  返回类型 method() [default 默认值];

  .......

}

 

package com.tanlei.URL;

public class MyAnnotation {
    @MyAnnotation1
     public MyAnnotation() {
        
    }
    @MyAnnotation2(color=Color.RED)
    //@MyAnnotation2(value= {"zhangsa","lisi"})
    // @MyAnnotation2(value = "tanlei" ,age=18)
    public static void main(String[] args) {
         @MyAnnotation1  
         int num=10;
    }
}
enum Color{
    RED,BLUE,YELLOW;
}

//标记注解
@interface MyAnnotation1{
    
}

//标记注解
@interface MyAnnotation2{
    //String value() default "李四";
    //int age();
    //String [] value();
    Color color();
}

 

 

Meta Annotation

元注解,可以对其他的注解进行修饰

@Retention

@Target

@Documented

@Inherited

 

Annotation

原文:https://www.cnblogs.com/tanlei-sxs/p/10041678.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!