Java注解
发布日期:2021-05-10 08:16:45 浏览次数:10 分类:精选文章

本文共 3190 字,大约阅读时间需要 10 分钟。

���������Annotation������Java���������������������������������������JDK 5.0������������������������������������������������������������������������������������������������������������������������@���������������������������������������������������������������������������������������name=value���������������������������������������������������������������������������������������������������������������������������������������������������


���������������

  • ���������������������������������������������������������������������������������������������������
  • ���������������������������������������������������������������������������������������������������������
  • ���������������������������������������Spring���MyBatis���������������������������������������������������

JDK������������

JDK���������������������������������������������

  • @Override������������������������������������
  • @Deprecated������������������������������������������������������������������
  • @SuppressWarnings���������������������������������������������������������������������

  • ������������Meta-Annotation���

    ������������������������������������������������������������

  • @Retention���������������������������������������������������������������������������
    • ���������@Retention(RetentionPolicy.SOURCE) ���������������������������������������
  • @Target������������������������������������������������������������������������
    • ���������@Target(ElementType.METHOD) ������������������������������������
  • @Documented������������������������������������Javadoc������������
  • @Inherited���������������������������������������������

  • ���������������

    ������������������������������������������������������������������������

  • ������������������

    ������@interface���������������������������������������������������Annotation���

    @Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)public @interface MyAnnotation {    String value() default "���������";    //������������������
  • ������������������

    ���������������������������������������������������������String���Class������������������������������������������������������������������������������

    @MyAnnotation("������������")  class TestClass {    // ...
  • ������������������������

    ������Class������API���������������������

    Class
    cls = TestClass.class;MyAnnotation annotation = cls.getAnnotation(MyAnnotation.class);String value = annotation.value();

  • ���������������������������

    • ���������������������@author���@version���@see���������������Javadoc���������

    • ���������������������������@param���@return���@exception������������������������������������

    • ���������������������@SuppressWarnings���������������������

    • ������������������Spring���������������������������������������bean������������������������������


    ���������������

    ���������������������������������

    @Target(ElementType unlawApi)@Retention(RetentionPolicy.RUNTIME)public @interface IllegalAPI {    String reason() default "���������";}

    ���������������

    @IllegalAPI(reason = "������������������")public class IllegalFunction {    // ...}

    ������������������������������������������Java���������������������������������������������������������������������������������������������������������������������������������������

    上一篇:Java反射
    下一篇:listBox移动全部数据到另一个listBox

    发表评论

    最新留言

    能坚持,总会有不一样的收获!
    [***.219.124.196]2025年04月14日 18时20分10秒