我在我的代码中使用 ICE。我想运行需要 GameObserverPrx 作为参数的函数。我不想按值传递 GameObserver,我在切片接口中使用 GameObserver* 来传递代理。
我应该使用什么函数将 GameObserver 转换为 GameObserverPrx?第二个问题 - 为什么 ICE 不能代替我做呢?我在网上搜索答案。我只找到了 ObjectAdapter.checkedCast 但它用于另一个目的。
这是错误:
GameProxyImpl 类型中的方法 addObserver(String, GameObserverPrx, Current) 不适用于参数 (String, GameObserverImpl, null) PrzeciwnikKomputerowy.java /warcaby-serwer/src/main/java/sr/warcaby/serwer 第 74 行 Java 问题
以下是我的代码片段: 在这一行中,我看到了一个错误。
partia.addObserver(token, new GameObserverImpl(this)), null);
GameObserver 实现的片段:
class GameObserverImpl extends _GameObserverDisp { //extends IGameObserverPOA{
private static final long serialVersionUID = 1L;
PrzeciwnikKomputerowy p;
public GameObserverImpl(PrzeciwnikKomputerowy p) {
this.p = p;
}
api.ice 的片段:
interface GameObserver {
void notifyObserver( CORBAMove lastMove);
};
interface GameProxy {
void addObserver( string token, GameObserver* o) throws MyException;
bool isMyTurn( string token) throws MyException;
void doMove( string token, CORBAMove move) throws MyException;
Position getPosition( string token) throws MyException;
string showPosition( string token) throws MyException;
};
不要对 CORBAMove 这个名字感到困惑。我使用了 CORBA,但我将代码更改为 ICE。