zoukankan      html  css  js  c++  java
  • Java

    Java - 注解 (Annotation)
     
    一、基本的 Annotation
        > 使用 Annotation 时要在其前面增加 @符号,并把该 Annotation 当成一个修饰符使用,用于修饰它支持的程序元素
     
    1、三个基本的 Annotation :
        > @Override:限定重写父类方法,该注释只能用于方法
        > @Deprecated:用于表示某个程序元素(类,方法等)已过时
        > @SuppressWarnings:抑制编译器报警
     
    2、自定义注解
    public @interface MyAnnotation{
        String value() default  "hello";    // 默认值
    }
    @MyAnnotation(value = "heyan")
     
    3、元注解:给注解做注解
        > Retention:只能用于修饰一个 Annotation  定义,用于指定该 Annotation  可以保留多长时间,@Retention 包含一个
                RetentionPolicy类型的成员变量,使用@Rentention 时必须为该value 成员变量指定值:
            > RetentionPolicy.SOURCE:编译器直接丢掉这种策略的注释
            > RetentionPolicy.CLASS:系统默认值,编译器将把注释记录在class文件中,当运行Java程序时,JVM不会保留注解
            > RetentionPolicy.RUNTIME:编译器将把注释记录在class文件中,当运行Java程序时,JVM会保留注释,程序可以
                通过反射取得该注解
        > Target:用于修饰一个 Annotation  定义,用于指定被修饰的 Annotation 能用于修饰哪些程序元素,@Target 也包含
            一个名为value的成员变量
        > Documented:用于指定被该元 Annotation 修饰的 Annotation 类将被javadoc工具提取成文档
            > 定义为@Documented 的注解必须设置Retention值为RUNTIME
        > Inherited:被他修饰的 Annotation 将具有继承性,如果某个类使用了被 @Inherited 修饰的 Annotation,则其子类将自
            动具有该注解 (实际应用中不是很多)
  • 相关阅读:
    【转】React Native 关于箭头函数、普通函数与点击事件的调用
    【转】React Native Config.h not found ( glog-0.3.4 )
    微软必应Bing搜索引擎这几天无法访问!
    Beyond Compare 4 提示错误“这个授权密钥已被吊销”的解决办法
    flock
    Getting.Started.with.Unity.2018.3rd.Edition
    Joe Hocking
    Unity 2018 By Example 2nd Edition
    Unity 2017 Game Optimization 新版
    Why is it called “armature” instead of “skeleton”? or perhaps “rig”?
  • 原文地址:https://www.cnblogs.com/kafeibuku/p/4988280.html
Copyright © 2011-2022 走看看