How to create an Object to an in interface which is having generics
在实例化接口时,我面临着以下困难。
1 2 3 4 5 | public interface HostSender < T extends Serializable, R extends Serializable> { } public class MySender implements HostSender< MessageRequest, MessageResponse> { } |
问题:
1 |
有人能告诉我如何为上面的语句创建对象吗?我试着用下面的方法找新的接线员,但不管用。
1 2 | messageSender = new MySender<MessageRequest, MessageResponse> (); messageSender = new MySender (); |
您的类"mysender"不是一般类。因此,您必须使用:
1 2 | HostSender< ? extends Serializable, ? extends Serializable> messageSender= null; messageSender = new MySender(); |