📄 debugproxy.java
字号:
/****************************************************
* 参考书籍:<<Java面向对象编程>> *
* 技术支持网址:www.javathinker.org *
***************************************************/
package reflect.sample;
import java.lang.reflect.*;
public class DebugProxy implements InvocationHandler
{
protected Object targetObj;
public DebugProxy(Object aTargetObject)
{
targetObj = aTargetObject;
}
public Object invoke(Object theProxy, Method method, Object[] params)
throws Throwable
{
try
{
// Print out the name of the method you are invoking
System.out.print("invoking "+method.getName()+"(");
// Print out the parameters
for (int i=0; i < params.length; i++)
{
if (i > 0) System.out.print(",");
System.out.print(params[i]);
}
System.out.print(") -> ");
// Invoke the real method on the target object
Object retval = method.invoke(targetObj, params);
// Print out the result
System.out.println(retval);
return retval;
}
catch (InvocationTargetException exc)
{
// If the method threw an exception, get the exception
Throwable error = exc.getTargetException();
// Print out the exception
System.out.println("threw "+error.toString());
// Throw it back to the caller
throw error;
}
catch (Exception exc)
{
// If there's an error just trying to invoke the method, print it out
System.out.println("Got error: "+exc.toString()+
" while invoking method");
throw exc;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -