服务器:
Registry registry = LocateRegistry.createRegistry(1099);
InventoryInterface Inventory = new Inventory(registry);
registry.bind("Inventory", Inventory);
客户:
Registry registry = LocateRegistry.getRegistry(1099);
InventoryInterface inventory = (InventoryInterface) registry.lookup("Inventory");
String product_id = inventory.newProduct();
ProductFacade product_1 = (ProductFacade) registry.lookup(product_id);
问题是在铸造时发生异常,在这种情况下,它发生在:ProductFacade product_1 = (ProductFacade) registry.lookup(product_id);
例外:
Exception in thread "main" java.lang.ClassCastException: com.sun.proxy.$Proxy2 cannot be cast to rmi.ProductFacade