覆盖函数中的抽象

时间:2011-08-16 08:13:33

标签: java

我想为send()

添加一个额外的参数

在DumpSequence.java中:

private static Receiver sm_receiver = new DumpReceiver(System.out, true);

sm_receiver.send(message, lTicks); (Work)
sm_receiver.send(message, lTicks, addParam1); (Won't work)

DumnpReceiver.java我试图添加额外的参数,即lTimeStamp2:

public void send(MidiMessage message, long lTimeStamp, long lTimeStamp2) {...}

错误:

DumpSequence.java:136: send(javax.sound.midi.MidiMessage,long) in javax.sound.mi
di.Receiver cannot be applied to (javax.sound.midi.MidiMessage,long,long)
                sm_receiver.send(message, lTicks, lTicks);
                           ^
.\DumpReceiver.java:21: DumpReceiver is not abstract and does not override abstr
act method send(javax.sound.midi.MidiMessage,long) in javax.sound.midi.Receiver
public class DumpReceiver
       ^
2 errors

4 个答案:

答案 0 :(得分:1)

从第21行删除@Override注释

答案 1 :(得分:0)

如果扩展抽象类,则需要定义所有抽象方法,或者它需要是抽象类。

或者如果您正在重载方法,则只需删除@Override注释

另见

答案 2 :(得分:0)

如果您想致电send(MidiMessage message, long lTimeStamp, long lTimeStamp2),则需要使用DumpReceiver个实例,而不是Receiver个实例。在`Receiver

中没有这样的方法
private static DumpReceiver sm_receiver = new DumpReceiver(System.out, true);
通过继承

编辑,您仍然可以将其用作普通Receiver对象。

答案 3 :(得分:0)

即使您不使用它,您仍然必须实施send(javax.sound.midi.MidiMessage,long) - 您实施的界面需要它