我有一个抽象的泛型类:
public abstract class AbstractMessageHandler<T extends AbstractMessageHandler>
{
public abstract List<String> getTypesOfMessages();
public abstract void handleMessage(String message, CometClient client);
public T setResponseValues(AbstractMessage request, T response )
{
response.setCompanyId(request.getCompanyId());
response.setMessageGroup(request.getMessageGroup());
response.setUserId(request.getUserId());
response.setTimeStamp(AbstractMessage.getCurrentTimeStamp());
return response;
}
}
我希望泛型子类成为此类的子类。换句话说,泛型必须是AbstractMessageHandler的子类。然而,这会导致编译问题。有谁能告诉我我做错了什么吗?
谢谢
T
是AbstractMessageHandler
理论上实现的interface
,我想这个interface
的名称是MessageHandler
。相关地,setResponseValues
最有可能将其参数作为Message
而不是AbstractMessage
。除非没有它们实现的interface
,否则这些要求是不必要的限制。 - pickypgAbstractMessageHandler<T extends AbstractMessage>?
- Jeremy Roman