helloserviceproxyfactory.java
来自「java写的一个静态代理的例子 大家看看 虽u然小 但能是说明问题」· Java 代码 · 共 22 行
JAVA
22 行
package proxy;
import java.lang.reflect.*;
public class HelloServiceProxyFactory {
public static HelloService getHelloServiceProxy(final HelloService helloService){
InvocationHandler handler=new InvocationHandler(){
public Object invoke(Object proxy,Method method,Object args[])throws Exception{
System.out.println("before calling "+method);
Object result=method.invoke(helloService,args);
System.out.println("after calling "+method);
return result;
}
};
Class classType=HelloService.class;
return (HelloService)Proxy.newProxyInstance(classType.getClassLoader(),
new Class[]{classType},
handler);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?