我想说我想将以下RMI-IIOP导出对象的远程引用传递给接收者(这是另一个远程对象):
public interface MyInterface extends Remote
{
public void send(Receiver receiver);
public String sayHello();
}
public class MyObject implements MyInterface
{
public MyObject()
{
PortableRemoteObject.exportObject(this); // I know I could extend PortableRemoteObject instead
}
public void send(Receiver receiver)
{
// which one is correct?
/* 1. */ receiver.receive(this);
/* 2. */ receiver.receive(this.toStub());
/* 3. */ // other things, such as narrow...
}
public String sayHello() { return "hello"; }
}
这是receive方法的实现:
public void receive(Remote remote)
{
MyInterface myObjectRef = (MyInterface) PortableRemoteObject.narrow(remote, MyInterface.class);
System.out.println(myObjectRef.sayHello());
}
目标是sayHello()方法的正确远程调用。
感谢。
答案 0 :(得分:1)
它们是等价的。 RMI的语义规定导出的远程对象作为自己的存根传递。