2014-07-10 62 views
1

那麼,什麼是與覆蓋我不的問題得到它:的Java約@覆蓋

@Override 
public ProtocolEncoder getEncoder(IoSession session) throws Exception { 
    return encoder; 
} 
@Override 
public ProtocolDecoder getDecoder(IoSession session) throws Exception { 
    return decoder; 
} 

錯誤:

error: method does not override or implement a method from a supertype 
@Override 

error: MaplePacketDecoder is not abstract and does not override abstract method doDecode(IoSession,ByteBuffer,ProtocolDecoderOutput) in CumulativeProtocolDecoder 
public class MaplePacketDecoder extends CumulativeProtocolDecoder { 

error: method write in interface ProtocolEncoderOutput cannot be applied to given types; 
       out.write(IoBuffer.wrap(ret)); 
    required: ByteBuffer 
    found: IoBuffer 
    reason: actual argument IoBuffer cannot be converted to ByteBuffer by method invocation conversion 
+2

你的超級類型是什麼? –

+2

你認爲覆蓋是什麼意思?因爲如果你知道這意味着什麼,那麼這個信息是非常清楚的。 –

+0

那麼你如何建議我寫它>? – UnityNewb

回答

2

你忘了執行doDecode(IoSession,ByteBuffer,ProtocolDecoderOutput)

0

看來,您嘗試覆蓋的方法名稱或您提供的參數不正確。你也不要從CumulativeProtocolDecoder實現doDecode方法。如果CumulativeProtocolDecoder是一個抽象類,您應該實現它。

1

你試圖用不同的參數(不同的簽名)覆蓋超類中的方法。重寫的方法必須匹配被覆蓋的方法的簽名(在父類中)。

http://docs.oracle.com/javase/tutorial/java/IandI/override.html

+0

「匹配」表示具有完全相同的名稱和參數類型。此外,如果方法的返回類型既不是原始方法的類型,也不是該類型的子類型,則重寫將產生不同的錯誤。 (如文檔參考文檔+1所述。) –