EventListener 接口中的 handleEvent 方法未在实现中实现 class
handleEvent method in EventListener interface not implemented in the implementing class
EventListener
接口声明了 handleEvent(Event evt)
方法,并在下面的代码中 GeneratorListener
扩展了该接口。有人告诉我这段代码是正确的。但是我不明白为什么打印机 class 不必 实现 handleEvent
方法?不是说一个接口里面的所有方法都要实现吗?
public interface GeneratorListener extends EventListener {
void objectGenerated(String object);
}
public class Printer implements GeneratorListener {
public void objectGenerated(String object) {
System.out.println(object);
}
}
看来我知道答案了。
方法
public void handleEvent(Event evt);
包含在 org.w3c.dom.events.EventListener 中。
但是在您的 GeneratorListener 界面中,您可能导入了看起来像
的 java.util.EventListener
package java.util;
/**
* A tagging interface that all event listener interfaces must extend.
* @since JDK1.1
*/
public interface EventListener {
}
因此您的 Printer class 实现了 Printer class 层次结构中唯一的抽象方法。这就是为什么您的代码是正确的。
EventListener
接口声明了 handleEvent(Event evt)
方法,并在下面的代码中 GeneratorListener
扩展了该接口。有人告诉我这段代码是正确的。但是我不明白为什么打印机 class 不必 实现 handleEvent
方法?不是说一个接口里面的所有方法都要实现吗?
public interface GeneratorListener extends EventListener {
void objectGenerated(String object);
}
public class Printer implements GeneratorListener {
public void objectGenerated(String object) {
System.out.println(object);
}
}
看来我知道答案了。 方法
public void handleEvent(Event evt);
包含在 org.w3c.dom.events.EventListener 中。 但是在您的 GeneratorListener 界面中,您可能导入了看起来像
的 java.util.EventListenerpackage java.util;
/**
* A tagging interface that all event listener interfaces must extend.
* @since JDK1.1
*/
public interface EventListener {
}
因此您的 Printer class 实现了 Printer class 层次结构中唯一的抽象方法。这就是为什么您的代码是正确的。