接口:
package proxy;
public interface IBusiness {
void doBusiness();
}被代理类:
package proxy;
public class BusinessImpl implements IBusiness{
public void doBusiness() {
System.out.println("doBusiness()");
}}
拦截类:
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;public class BusinessInterceptor implements InvocationHandler {
private IBusiness biz;
public Object invoke(Object arg0, Method arg1, Object[] arg2)
throws Throwable {
System.out.println("before");
Object obj = arg1.invoke(biz, arg2);
System.out.println("after");
return obj;
}
public BusinessInterceptor(IBusiness biz) {
this.biz = biz;
}

}
测试类:
package proxy;import java.lang.reflect.Proxy;/*
 * 静态代理
 */
public class Test {
public static void main(String[] args) {
BusinessImpl biz = new BusinessImpl();
BusinessInterceptor proxy = new BusinessInterceptor(biz);
Object bus = Proxy.newProxyInstance(biz.getClass().getClassLoader(),IBusiness.class.getInterfaces(),proxy);
System.out.println(bus instanceof BusinessImpl);
((IBusiness)bus).doBusiness();
}
}问题:
false
Exception in thread "main" java.lang.ClassCastException: $Proxy0
at proxy.Test.main(Test.java:14)怎么报异常了?????