?? myinvokationhandler.java
字號:
import java.lang.reflect.*;
/**
* Description:
* <br/>Copyright (C), 2008-2010, Yeeku.H.Lee
* <br/>This program is protected by copyright laws.
* <br/>Program Name:
* <br/>Date:
* @author Yeeku.H.Lee kongyeeku@163.com
* @version 1.0
*/
public class MyInvokationHandler implements InvocationHandler
{
//需要被代理的對象
private Object target;
public void setTarget(Object target)
{
this.target = target;
}
//執行動態代理對象的所有方法時,都會被替換成執行如下的invoke方法
public Object invoke(Object proxy, Method method, Object[] args)
throws Exception
{
DogUtil du = new DogUtil();
//執行DogUtil對象中的method1。
du.method1();
//以target作為主調來執行method方法
Object result = method.invoke(target , args);
//執行DogUtil對象中的method2。
du.method2();
return result;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -