RMI: strange inheritance behavior of Remote interface
843793Feb 17 2006 — edited Feb 20 2006Hello all,
I've encountered a strange inheritance problem using RMI. Consider the following interfaces and classes :
public interface Product extends Remote {
public void doX() throws RemoteException;
}
public interface LocalProduct extends Product {
public void doX();
}
public class RMIServer {
public static void main(String[] args) {
try {
Product p = new ProductImpl();
UnicastRemoteObject.exportObject(p,0);
Naming.rebind("product", p);
} catch( Exception e) {
System.err.println(e);
}
}
If 'ProductImpl' is written like this, i.e. directly implements Product, everything works fine
public class ProductImpl implements Product {
public void doX() {
System.out.println("Do X called");
}
}
If 'ProductImpl' implements LocalProduct, an exception is throws:
public class ProductImpl implements LocalProduct {
public void doX() {
System.out.println("Do X called");
}
}
result in :
remote object implements illegal remote interface; nested exception is:
java.lang.IllegalArgumentException: illegal remote method encountered: public abstract void LocalProduct.doX()
So, when the concrete class directly implements the Product interface everything is ok, but when there is an intermediate interface (which is for local use), an exception is thrown.
Does anyone have any idea why this is the case?
Thanks in advance!
Gunther.