• zbb20181224 java,annotation 注解,自定义注解解析2


    InitField.java

    package com.zbb.app.annotation;

    import java.lang.annotation.Documented;
    import java.lang.annotation.ElementType;
    import java.lang.annotation.Inherited;
    import java.lang.annotation.Retention;
    import java.lang.annotation.RetentionPolicy;
    import java.lang.annotation.Target;

    @Documented
    @Inherited
    @Target({ ElementType.FIELD, ElementType.METHOD })
    @Retention(RetentionPolicy.RUNTIME)
    public @interface InitField {
         public String value() default "";
    }


    Test.java

    package com.zbb.app.annotation;

    import java.lang.reflect.InvocationTargetException;

    public class Test {
         public static void main(String[] args)
                 throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
             User user = UserFactory.create();

    //        User user = new User();
             System.out.println(user.getName());
             System.out.println(user.getAge());
         }
    }


    User.java

    package com.zbb.app.annotation;

    public class User {
         private String name;
         private String age;

        public String getName() {
             return name;
         }

        @InitField(value = "zbb")
         public void setName(String name) {
             this.name = name;
         }

        public String getAge() {
             return age;
         }

        @InitField(value = "123")
         public void setAge(String age) {
             this.age = age;
         }
    }

  • 相关阅读:
    Solution: Win 10 和 Ubuntu 16.04 LTS双系统, Win 10 不能从grub启动
    在Ubuntu上如何往fcitx里添加输入法
    LaTeX 笔记---Q&A
    Hong Kong Regional Online Preliminary 2016 C. Classrooms
    Codeforces 711E ZS and The Birthday Paradox
    poj 2342 anniversary party
    poj 1088 滑雪
    poj 2479 maximum sum
    poj 2481 cows
    poj 2352 stars
  • 原文地址:https://www.cnblogs.com/super-admin/p/10167208.html
Copyright © 2020-2023  润新知