public class App { public static void main(String[] args) { Inter vo = (Inter) Proxy.newProxyInstance(App.class.getClassLoader(), VO.class.getInterfaces(), new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (args[0].getClass() == VO.class) { System.out.println("相同"); } return null; } }); vo.getString(new VO()); } }interface Inter { public void getString(VO v); }class VO implements Inter { public void getString(VO v) { System.out.println("--------------"); } }
if (args[0] instanceof VO) { System.out.println("相同"); }
没明白=。=invoke方法invoke(Object proxy, Method method,Object[] args),参数args怎么转化成getMethod的参数Class<?>...parameterTypes这种类型啊
public class App {
public static void main(String[] args) {
Inter vo = (Inter) Proxy.newProxyInstance(App.class.getClassLoader(), VO.class.getInterfaces(), new InvocationHandler() { @Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (args[0].getClass() == VO.class) {
System.out.println("相同");
}
return null;
}
});
vo.getString(new VO()); }
}interface Inter {
public void getString(VO v);
}class VO implements Inter { public void getString(VO v) {
System.out.println("--------------");
}
}
if (args[0] instanceof VO) {
System.out.println("相同");
}
System.out.println("相同");
}