33 lines
813 B
Java
33 lines
813 B
Java
package me.ehlxr.proxy;
|
|
|
|
import java.lang.reflect.InvocationHandler;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.Method;
|
|
|
|
/**
|
|
* @author lixiangrong
|
|
* @since 2019-06-28.
|
|
*/
|
|
public class MyInvocationHandler implements InvocationHandler {
|
|
private Bird bird;
|
|
|
|
public MyInvocationHandler(Bird bird) {
|
|
this.bird = bird;
|
|
}
|
|
|
|
@Override
|
|
public Object invoke(Object proxy, Method method, Object[] args) {
|
|
long start = System.currentTimeMillis();
|
|
|
|
try {
|
|
method.invoke(bird, args);
|
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
long end = System.currentTimeMillis();
|
|
System.out.println("Fly time = " + (end - start));
|
|
return null;
|
|
}
|
|
}
|