在界面中,我应该为每个方法使用try-catch或throws?

use*_*881 0 java interface

public interface RMIInterface extends Remote {
    public byte[] geScreen() throws RemoteException;
    public byte[] getProcessList() throws RemoteException;
    public boolean execute(String command) throws RemoteException;
    public boolean messageTo(String msg,String user) throws RemoteException;
    public boolean saveImage(byte[] image,String user) throws RemoteException;
    public byte[][] getimages(String user,String date)throws RemoteException;
}
Run Code Online (Sandbox Code Playgroud)

上面的RMI接口方法抛出RemoteException,如果我将这些方法包含在try中,并且捕获RemoteException就可以了.

Ruc*_*era 8

你不能在接口中使用try-catch,因为这里没有实现,只有规范/收缩.相反,你可以throws <exception list>像你已经做的那样使用它.