posts - 431,  comments - 344,  trackbacks - 0
          公告
           Don't Repeat Yourself
          座右銘:you can lose your money, you can spent all of it, and if you work hard you get it all back. But if you waste your time, you're never gonna get it back.
          公告本博客在此聲明部分文章為轉(zhuǎn)摘,只做資料收集使用。


          微信: szhourui
          QQ:109450684
          Email
          lsi.zhourui@gmail.com
          <2008年4月>
          303112345
          6789101112
          13141516171819
          20212223242526
          27282930123
          45678910

          留言簿(15)

          隨筆分類(1019)

          文章分類(3)

          文章檔案(21)

          收藏夾

          Link

          好友博客

          最新隨筆

          搜索

          •  

          積分與排名

          • 積分 - 863183
          • 排名 - 44

          最新評論

          閱讀排行榜

          編寫Annotation:

          package com.eric.news.cha06;

          import Java.lang.annotation.Documented;
          import Java.lang.annotation.Inherited;
          import Java.lang.annotation.Retention;
          import Java.lang.annotation.RetentionPolicy;

          @Documented
          @Inherited
          @Retention(RetentionPolicy.RUNTIME)
          public @interface GroupTODO {

           public enum Severity {CRITICAL, IMPORTANT, TRIVIAL, DOCUMENTATION};
           Severity severity() default Severity.IMPORTANT;
           String item();
           String assignedTo();
          }

          ---------------------
          運用annotation:

          package com.eric.news.cha06;

          @InProgress
          public class TestInProgress {

           @GroupTODO(
             severity=GroupTODO.Severity.CRITICAL,
             item="Figure out the amount of interest per month",
             assignedTo="Eric Zhou"
           )
           public void calculateInterest(float amount, float rate) {
            
           }
          }


          ---------------------

          測試:

          package com.eric.news.cha06;

          import Java.lang.reflect.Method;

          public class TestAnnotation {


           public static void main(String[] args) throws SecurityException, NoSuchMethodException {
            Class c = TestInProgress.class;
            Method element = c.getMethod("calculateInterest", float.class, float.class);
            
            GroupTODO groupTodo = element.getAnnotation(GroupTODO.class);
            String assignedTo = groupTodo.assignedTo();
            
            System.out.println(assignedTo);
            System.out.println(groupTodo.item());

           }

          }


          ---------------------
          結(jié)果:
          Eric Zhou
          Figure out the amount of interest per month


          posted on 2008-04-30 15:25 周銳 閱讀(200) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 兴和县| 二连浩特市| 斗六市| 孟津县| 尤溪县| 丹凤县| 南陵县| 施秉县| 石狮市| 南召县| 通榆县| 庆云县| 岑巩县| 平南县| 秦安县| 延川县| 察哈| 都匀市| 永靖县| 施秉县| 荔波县| 亚东县| 开远市| 建宁县| 和平区| 犍为县| 通化市| 谷城县| 唐河县| 丰镇市| 天全县| 西青区| 福鼎市| 凤冈县| 阿城市| 诸城市| 屏南县| 孟州市| 四川省| 泸西县| 崇左市|