我正在尝试使用泛型来接受任何实现Client
接口的对象,但我似乎无法做到正确。
public interface Client {
public void makeMove();
}
public MyClient implements Client {
public MyClient(Server server) {
server.connectClient(this);
}
}
我上面得到的错误是:The method connectClient(Class<? extends FanoronaClient>) in the type Server is not applicable for the arguments (GUIClient)
具有泛型的服务器:
public class Server {
private Class<? extends Client> client_;
public void connectClient(Class<? extends Client> client) {
client_ = client;
client_.makeMove(); // type error here
}
}
这里的错误是The method makeMove() is undefined for the type Class<capture#7-of ? extends Client>
我究竟做错了什么?