zoukankan      html  css  js  c++  java
  • 【Java】-NO.17.EBook.4.Java.1.014-【疯狂Java讲义第3版 李刚】- Annotation

     1.0.0 Summary

    Tittle:【Java】-NO.17.EBook.4.Java.1.014-【疯狂Java讲义第3版 李刚】-  Annotation

    Style:EBook

    Series:Java

    Since:2017-11-01

    End:....

    Total Hours:...

    Degree Of Diffculty:2

    Degree Of Mastery:2

    Practical Level:2

    Desired Goal:2

    Archieve Goal:....

    Gerneral Evaluation:...

    Writer:kingdelee

    Related Links:

    http://www.cnblogs.com/kingdelee/

    1.java.lang 的 5个Annotation

    api :https://docs.oracle.com/javase/9/docs/api/java/lang/package-summary.html

    Annotation Types Summary
    Annotation TypeDescription
    Deprecated
    A program element annotated @Deprecated is one that programmers are discouraged from using.
    FunctionalInterface
    An informative annotation type used to indicate that an interface type declaration is intended to be a functional interface as defined by the Java Language Specification.
    Override
    Indicates that a method declaration is intended to override a method declaration in a supertype.
    SafeVarargs
    A programmer assertion that the body of the annotated method or constructor does not perform potentially unsafe operations on its varargs parameter.
    SuppressWarnings
    Indicates that the named compiler warnings should be suppressed in the annotated element (and in all program elements contained in the annotated element).

    2.java.lang.annotation 的 6个meta Annotation

    https://docs.oracle.com/javase/9/docs/api/java/lang/annotation/package-summary.html

    Annotation Types Summary
    Annotation TypeDescription
    Documented
    If the annotation @Documented is present on the declaration of an annotation type A, then any @A annotation on an element is considered part of the element's public contract.
    Inherited
    Indicates that an annotation type is automatically inherited.
    Native
    Indicates that a field defining a constant value may be referenced from native code.
    Repeatable
    The annotation type java.lang.annotation.Repeatable is used to indicate that the annotation type whose declaration it (meta-)annotates is repeatable.
    Retention
    Indicates how long annotations with the annotated type are to be retained.
    Target
    Indicates the contexts in which an annotation type is applicable.

    2.1 @Retention

    当需要使用的注解考虑在运行时可以被程序反射读取,则在该注解上加 

    @Retention(RetentionPolicy.RUNTIME)
    public @interface MyAnnotation{}
    

      

    2.2 @Target

     用于指定注解修饰的作用域

    // 我定义的注解只能修饰成员变量
    @Target(ElementType.FIELD)
    public @interface MyAnnotation{}
    

      

    2.3 @Document

    指定可以被提取出文档,一般需要出现在文档的都是必写。

     2.4 @Inherited

    类B继承类A,类A使用@Inherited时,类B同样继承了类A的@Inherited特性

    2.5 @Repeatable

    3. 反射获取注解信息

  • 相关阅读:
    document.getElementById(“id”)与$("#id")的区别
    sqlserver 无法打开备份文件a.bak
    xnconvert 图片转换工具
    基于jQuery的 h5移动端抽奖页面插件
    nodeJS 简单启动express服务器
    jquery 按钮切换插件
    微信判断手机有没有APP,有则打开,没有则跳到应用商城
    jQuery 文字向上轮播
    Node.js制作爬取简书内容的爬虫
    jquery手机端轮播图,点击放大手动轮播
  • 原文地址:https://www.cnblogs.com/kingdelee/p/7768120.html
Copyright © 2011-2022 走看看