我正在使用 RMI 创建一个即时聊天应用程序。服务器通过我需要客户端处理的某些对象发送。例如,服务器将发送一个JoinedGroupOperation
类。在我的客户端应用程序中,我需要识别类并让我的处理程序接管(HandleJoinedGroupOperation
)。这个类将在客户端做很多事情。
我的问题是如何处理来自服务器的类,所以我不需要做任何 if 语句?IE
if(server.getResponse() instanceof JoinedGroupOperation){
HandleJoinedGroupOperation handle = new HandleJoinedGroupOperation();
handle.foo();
}