天空是藍色的

          做好軟件為中國 #gcc -c helloworld.c -o helloworld.o //編譯目標文件 #gcc helloworld.o -o helloworld //編譯成可執行exe #helloworld //運行exe
          數據加載中……
          初步看了java動態代理
          ProxyClass.java
          import java.lang.reflect.InvocationHandler;
          import java.lang.reflect.InvocationTargetException;
          import java.lang.reflect.Proxy;

          public class ProxyClass {
              
          public static void main(String arags[]) throws IllegalArgumentException,
                      SecurityException, InstantiationException, IllegalAccessException,
                      InvocationTargetException, NoSuchMethodException 
          {
                  InvocationHandler handler 
          = new MyInvocationHandler();
                  Class proxyClass 
          = Proxy.getProxyClass(Foo.class.getClassLoader(),
                          
          new Class[] { Foo.class });
                  Foo f 
          = (Foo) proxyClass.getConstructor(
                          
          new Class[] { InvocationHandler.class }).newInstance(
                          
          new Object[] { handler });
                  f.doSomething();

              }

          }

          Foo.java
          public interface Foo {
              
          void doSomething();
          }
          MyInvocationHandler.java
          import java.lang.reflect.InvocationHandler;
          import java.lang.reflect.Method;

          public class MyInvocationHandler implements InvocationHandler {

              
          public Object invoke(Object proxy, Method method, Object[] args)
                      
          throws Throwable {
                  System.out.println(
          "Helloworld");
                  
          return null;
              }


          }

          posted on 2006-01-04 16:32 bluesky 閱讀(1276) 評論(3)  編輯  收藏 所屬分類: 工作總結

          評論

          # re: 初步看了java動態代理 2008-05-08 22:41 Flicker

          很簡單,但很說明問題
            回復  更多評論    

          # re: 初步看了java動態代理[未登錄] 2008-11-20 20:15 Java

          很失敗的文章
            回復  更多評論    

          # re: 初步看了java動態代理 2009-02-12 09:32 xx

          失敗的文章
            回復  更多評論    
          主站蜘蛛池模板: 洛浦县| 大足县| 岫岩| 定襄县| 三都| 桐柏县| 安岳县| 藁城市| 黔西县| 钦州市| 井冈山市| 苏尼特左旗| 伊川县| 福建省| 灌阳县| 文成县| 新邵县| 甘德县| 正安县| 运城市| 黄石市| 陇西县| 西藏| 石景山区| 辽宁省| 绥棱县| 靖宇县| 宿松县| 巴彦淖尔市| 雷波县| 富民县| 义马市| 精河县| 陆丰市| 江油市| 广宗县| 江达县| 仙居县| 银川市| 延寿县| 宜良县|