public class Experiment {
public static void main(String[] args){
Animal dog=(Animal)Proxy.newProxyInstance(
Animal.class.getClassLoader(),
new Class[]{Animal.class},
new InvocationHandler() {
long startTime=System.currentTimeMillis();
Dog dog=new Dog();
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
long startTime=System.currentTimeMillis();
Object obj=method.invoke(dog, args);
long endTime=System.currentTimeMillis();
long consumeTime=endTime-startTime;
System.out.println("方法用时"+consumeTime+"毫秒");
return obj;
}
});
dog.Shout();//错了。
}
}
class Dog implements Animal{
public void Shout(){
System.out.println("wang wang");
}
}
interface Animal{
public class Demo {
public static void main(String[] args){
Animal dog=(Animal)Proxy.newProxyInstance(
Animal.class.getClassLoader(),
new Class[]{Animal.class},
new InvocationHandler() {
long startTime=System.currentTimeMillis();
Dog dog=new Dog();
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
long startTime=System.currentTimeMillis();
Object obj=method.invoke(dog, args);
long endTime=System.currentTimeMillis();
long consumeTime=endTime-startTime;
System.out.println("方法用时"+consumeTime+"毫秒");
return obj;
}
});
dog.Shout();//错了。
}
}
class Dog implements Animal{
public void Shout(){
System.out.println("wang wang");
}
}
interface Animal{