2
我用java.lang.reflect.Proxy
代理对象。用泛型代理
我有这个类:
public class TransportableImpl extends Transportable{
public class OrderInvoker extends InvocationHandler{
...
}
}
在这里,我建立了代理:
Transportable t = new TransportableImpl();
Order myOrder = new OrderImpl();
Class proxyClass = Proxy.getProxyClass(getClass().getClassLoader(), Transportable.class, Order.class);
Object serializable = proxyClass.getConstructor(new Class[]{InvocationHandler.class}).newInstance(t.new OrderInvoker(myOrder));
问题是:类是原始类型和
Class<? extends Order & Transportable> proxyClass =
(Class<? extends Order & Transportable>)
Proxy.getProxyClass(getClass().getClassLoader(),
Transportable.class, Order.class);
是难以阅读。
任何想法?
难以阅读的问题是? –
是的。 '类>'不是精确的。 –
反问题:你想写什么,即你认为什么足够精确而又容易阅读?你能提供一些伪代码来帮助我们理解你的目标吗? – Thomas