Java Reference
In-Depth Information
Method method,
Object[] args,
MethodProxy alternativeMethod)
throws Throwable
{
String argsString = "";
if(args != null)
{
for(int i = 0; i < args.length; i++)
{
if(i > 0)
{
argsString += ", ";
}
argsString += args[i];
}
}
System.out.println("---> " +
method.getDeclaringClass().getName() +
"." + method.getName() +
"(" + argsString + ")");
try
{
Object result = alternativeMethod.invokeSuper(target,
args);
if(method.getReturnType() != void.class)
{
System.out.println("<--- return: " + result);
}
else
{
System.out.println("<--- return");
}
return result;
}
catch(Throwable t)
{
System.out.println("<--- exception: " + t.getMessage());
return null;
}
}
}
public class Main
{
private static void useCounter(CounterImpl counter)
{
//wie zuvor:
...
}
public static void main(String[] args)
{
try
{
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(CounterImpl.class);
enhancer.setCallback(new MyMethodInterceptor());
 
Search WWH ::




Custom Search