zoukankan      html  css  js  c++  java
  • 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;
         }
    }

  • 相关阅读:
    ubuntu 14.04 LTS 163更新源
    Windows 2008R2 修改SID
    ubuntu14 使用rsync远程备份文件
    vim常用
    Ubuntu创建lvm
    Windows 迁移本地用户配置文件到域用户
    Linux scp使用
    Centos 7 修改网卡名称、静态IP
    Axel多线程工具安装
    testlink 1.9.19安装
  • 原文地址:https://www.cnblogs.com/super-admin/p/10167208.html
Copyright © 2011-2022 走看看