天空是蓝色的

做好软件为中国 #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 阅读(1251) 评论(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

失败的文章
  回复  更多评论    

只有注册用户登录后才能发表评论。


网站导航: