JAVA SE Annotation(注解)

简介

注解 (Annotation):元数据,如同标签。一种代码级别的说明。

元注解 :一种基本注解,能够应用到其它的注解上面。

  • @Target //定义注解的作用目标
  • @Retention //定义注解的保留策略
  • @Inherited //说明子类可继承该注解
  • @Documented //说明该注解将写入javadoc中
  • @Repeatable //说明该注解的参数是可重复,注解的存储容器注解类型(1.8开始)

作用

  • 编写文档:通过注解生成文档(生成文档doc文档)
  • 代码分析:通过注解对代码进行分析(使用反射)
  • 编译检查:通过注解让编译器能够实现基本的编译检查(Override)

分类

按来源分类 ( JDK, 第三方, 自定义)

  • JDK自带
@Override //对重写的方法进行标记,没有重写到则编译器提示报错
@Deprecated //标注方法已过时或不提倡使用
@SuppressWarnings //取消警告显示
  • 第三方

Spring

//Spring
@Autowired
@Sercice
@Repository

Mybatis 

//Mybatis
@InsertProvider
@UpdateProvider
@Options
  • 自定义
//自定义注解
public @interface Description {
	String value();//一个成员默认命名为value
}

按运行阶段(源码,编译时,运行时)

  • 源码
  • 编译时
  • 运行时

应用

//annotation接口源码中注解的应用

package java.lang.annotation;

/**
 * @author  Josh Bloch
 * @since   1.5
 */
public interface Annotation {
    /**
     * @return true if the specified object represents an annotation
     *     that is logically equivalent to this one, otherwise false
     */
    boolean equals(Object obj);

    /**
     * @return the hash code of this annotation
     */
    int hashCode();

    String toString();

    /**
     * Returns the annotation type of this annotation.
     * @return the annotation type of this annotation
     */
    Class<? extends Annotation> annotationType();
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值