关于@Override的Java

时间:2014-07-10 20:53:27

标签: java netbeans

那么覆盖的问题是什么,我不明白:

@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

3 个答案:

答案 0 :(得分:2)

您忘了实施doDecode(IoSession,ByteBuffer,ProtocolDecoderOutput)

答案 1 :(得分:1)

您尝试使用不同的参数(不同的签名)覆盖超类中的方法。覆盖方法必须匹配被覆盖的方法的签名(在父类中)。

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

答案 2 :(得分:0)

您尝试覆盖的方法名称或您提供的参数似乎不正确。您也没有从CumulativeProtocolDecoder实现doDecode方法。如果CumulativeProtocolDecoder是一个抽象类,你应该实现它。