如果有这样的 TCP/UDP 通信工厂
public enum IoFactory {
// Singleton
INSTANCE;
public <T> Io<T> create(T type, TransportProtocol protocol) {
...
return ...;
}
}
创建Io
接口:
public interface Io<T> {
public void send(T msg);
public T receive();
}
但是,当我创建 with 的实例Io
时
IoFactory factory = IoFactory.INSTANCE;
Io<TestMessage> u = factory.create(TestMessage.class, TransportProtocol.UDP);
我收到一个编译错误,说正确的实例化应该是
Io<Class<TestMessage>> u = factory.create(TestMessage.class, TransportProtocol.UDP);
这是怎么回事?