zoukankan      html  css  js  c++  java
  • Java8-Annotations

    import java.lang.annotation.ElementType;
    import java.lang.annotation.Repeatable;
    import java.lang.annotation.Retention;
    import java.lang.annotation.RetentionPolicy;
    import java.lang.annotation.Target;
    
    public class Annotations1 {
    
        @Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE})
        @interface MyAnnotation {
    
        }
    
        @Retention(RetentionPolicy.RUNTIME)
        @interface Hints {
            Hint[] value();
        }
    
        @Repeatable(Hints.class)
        @Retention(RetentionPolicy.RUNTIME)
        @interface Hint {
            String value();
        }
    
        @Hint("hint1")
        @Hint("hint2")
        class Person {
    
        }
    
        public static void main(String[] args) {
            Hint hint = Person.class.getAnnotation(Hint.class);
            System.out.println(hint);   // null
    
            Hints hints1 = Person.class.getAnnotation(Hints.class);
            System.out.println(hints1.value().length);  // 2
    
            Hint[] hints2 = Person.class.getAnnotationsByType(Hint.class);
            System.out.println(hints2.length);  // 2
    
        }
    }
  • 相关阅读:
    NSURL 的简单实用
    动画demo
    UIScrollView的简单页面
    关于UITableview(更新)
    添加手势
    多线程
    IOS 瀑布流
    高低字节序转换(htonl、ntohl、htons、ntohs函数)
    Xcode个版本
    网址
  • 原文地址:https://www.cnblogs.com/bilaisheng/p/10210911.html
Copyright © 2011-2022 走看看