首先,如下爲該接口的註釋及代碼:html
package java.rmi; /** * The <code>Remote</code> interface serves to identify interfaces whose * methods may be invoked from a non-local virtual machine. Any object that * is a remote object must directly or indirectly implement this interface. * Only those methods specified in a "remote interface", an interface that * extends <code>java.rmi.Remote</code> are available remotely. * * <p>Implementation classes can implement any number of remote interfaces and * can extend other remote implementation classes. RMI provides some * convenience classes that remote object implementations can extend which * facilitate remote object creation. These classes are * <code>java.rmi.server.UnicastRemoteObject</code> and * <code>java.rmi.activation.Activatable</code>. * * <p>For complete details on RMI, see the <a href=../../../platform/rmi/spec/rmiTOC.html>RMI Specification</a> which describes the RMI API and system. * * @since JDK1.1 * @author Ann Wollrath * @see java.rmi.server.UnicastRemoteObject * @see java.rmi.activation.Activatable */ public interface Remote {}
從英文中咱們能夠得知,Remote接口,只是標明該接口是會被遠程調用的,而不是本地。當你須要編寫這樣的接口的時候,能夠繼承這個接口,而後寫本身獨有的接口方法,例以下面這樣:java
public interface HavanaInterface extends Remote{ public final String SERVICENAME = "havana"; //打印歌詞 public void printLyric(MySong song) throws RemoteException; }