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

          好友博客

          最新隨筆

          搜索

          •  

          積分與排名

          • 積分 - 865093
          • 排名 - 44

          最新評(píng)論

          閱讀排行榜

          編寫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();
          }

          ---------------------
          運(yùn)用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) {
            
           }
          }


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

          測(cè)試:

          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 周銳 閱讀(203) 評(píng)論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 枣强县| 达拉特旗| 永仁县| 乌兰县| 舟曲县| 金塔县| 尖扎县| 崇义县| 新源县| 渑池县| 武定县| 利辛县| 常宁市| 宽城| 正蓝旗| 泗水县| 呼图壁县| 南皮县| 镇雄县| 丰原市| 隆子县| 秦安县| 炎陵县| 临洮县| 仁怀市| 桐柏县| 新民市| 永平县| 神农架林区| 陵水| 内江市| 滁州市| 新乐市| 丰顺县| 兴国县| 临潭县| 南投县| 浮山县| 商丘市| 略阳县| 泽普县|