Annotation
Posted tanlei-sxs
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Annotation相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章