我在我的代碼中使用ICE。我想運行需要GameObserverPrx作爲參數的函數。我不想按價值傳遞GameObserver,並且我在切片接口中使用GameObserver *來傳遞代理。ICE - 如何將實現轉換爲代理?
我應該使用什麼函數將GameObserver投射到GameObserverPrx? 第二個問題 - 爲什麼ICE不會代替我做? 我在網上搜索答案。我只發現ObjectAdapter.checkedCast,但它用於另一個目的。
這裏是錯誤:
The method addObserver(String, GameObserverPrx, Current) in the type GameProxyImpl is not applicable for the arguments (String, GameObserverImpl, null) PrzeciwnikKomputerowy.java /warcaby-serwer/src/main/java/sr/warcaby/serwer line 74 Java Problem
下面是我的代碼片段: 在此行中我看到一個錯誤。 GameObserver實施
partia.addObserver(token, new GameObserverImpl(this)), null);
片段:api.ice的
class GameObserverImpl extends _GameObserverDisp { //extends IGameObserverPOA{
private static final long serialVersionUID = 1L;
PrzeciwnikKomputerowy p;
public GameObserverImpl(PrzeciwnikKomputerowy p) {
this.p = p;
}
片段:
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。