我有一个尝试与Java 8的RMI一起使用的应用程序。我在Windows 10上使用eclipse Neon.3,并且抱怨我没有实现不存在的接口方法。在尝试缩小单独的问题时,我注释了该接口的一种抽象方法。
在注释掉一个抽象方法之后,该接口将被导出到一个jar文件中。然后将jar文件添加到将实现该接口的服务器应用程序的构建路径中。
界面:
package accessService;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.HashMap;
public interface ApplicationAccessService extends Remote{
//public void connectClient(Long[] clientId) throws RemoteException;
public HashMap<String, Long> getClientConnections() throws RemoteException;
public HashMap<String, Integer> getServerConnections() throws RemoteException;
}
实现类:
package iap.util;
import java.rmi.RemoteException;
import java.util.HashMap;
import accessService.ApplicationAccessService;
public class RemoteIAP implements ApplicationAccessService{
private final static HashMap<String, Integer> SERVERS = new HashMap<>();
private final static HashMap<String, Long> CLIENTS = new HashMap<>();
public RemoteIAP(){ }
//methods used by RMI interface--------------------------------------
@Override
public HashMap<String, Integer> getServerConnections() throws RemoteException {
return SERVERS;
}
@Override
public HashMap<String, Long> getClientConnections() throws RemoteException {
return CLIENTS;
}
//end RMI methods-------------------------------------------------------
}
错误:
The type RemoteIAP must implement the inherited abstract method ApplicationAccessService.connectClient(Long[])
在我看来,日食以某种方式在注释掉有问题的方法之前一直保持工件。重新启动Eclipse并重新启动我的PC并没有采取任何措施来更改此行为。我不知道这是Java的问题,还是使用eclipse中的上下文菜单将接口添加到构建路径的方式,还是其他问题?
最佳答案
有时,ide可以读取旧的编译后的.class
文件,并且在构建操作后,它以某种方式不能替换为新的文件。
更改类名,然后重新构建。