編程生活

             :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            113 隨筆 :: 0 文章 :: 18 評論 :: 0 Trackbacks
          <2009年8月>
          2627282930311
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          留言簿(5)

          隨筆檔案

          搜索

          積分與排名

          最新評論

          public class DayFactory {
              
          static {
                  
          try {
                      Constructor con 
          = Day.class.getDeclaredConstructors()[0];
                      Method[] methods 
          = con.getClass().getDeclaredMethods();
                      
          for (Method m : methods) {
                          
          if (m.getName().equals("acquireConstructorAccessor")) {
                              m.setAccessible(
          true);
                              m.invoke(con, 
          new Object[0]);
                          }

                      }

                      Field[] fields 
          = con.getClass().getDeclaredFields();
                      Object ca 
          = null;
                      
          for (Field f : fields) {
                          
          if (f.getName().equals("constructorAccessor")) {
                              f.setAccessible(
          true);
                              ca 
          = f.get(con);
                          }

                      }

                      Method m 
          = ca.getClass().getMethod("newInstance"new Class[] { Object[].class });
                      m.setAccessible(
          true);
                      Day v 
          = (Day) m.invoke(ca, new Object[] new Object[] "VACATION", Integer.MAX_VALUE } });
                      System.out.println(v.getClass() 
          + ":" + v.name() + ":" + v.ordinal());
                      
          for(Day day:Day.values()) {
                          System.out.println(day);
                      }

                  }
           catch (Exception ex) {
                      ex.printStackTrace();
                  }

              }

              
              
          public static void say() {
              }

              
              @Test
              
          public void ddd() {
                  DayFactory.say();
              }

          posted on 2009-08-19 09:07 wilesun 閱讀(1507) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 浦县| 苍溪县| 德昌县| 诸暨市| 绥宁县| 泽州县| 土默特左旗| 藁城市| 盐源县| 德安县| 宜宾市| 通河县| 镇安县| 婺源县| 芦溪县| 民权县| 浦县| 晋宁县| 黄骅市| 吉林市| 图们市| 玉环县| 绥化市| 淳安县| 沈阳市| 曲阳县| 崇文区| 广西| 辉县市| 东阳市| 榆林市| 织金县| 射阳县| 嘉黎县| 叙永县| 木兰县| 湖州市| 慈利县| 阳山县| 灵寿县| 滦南县|