public interface ActionListener extends EventListener { /**
* Invoked when an action occurs.
*/
public void actionPerformed(ActionEvent e);}
public abstract class OutputAction extends ActionListener {
public OutputAction(ProgramInfo programInfo) {
this(programInfo, "出力");
}
public abstract void actionPerformed(ActionEvent e) throws OfsException;
}
上面连个类。。第二给类编译的时候有错。
Multiple ers at this line
- implements java.awt.event.ActionListener.actionPerformed
- Exception OfsException is not compatible with throws clause in
ActionListener.actionPerformed(ActionEvent)
WHY?
* Invoked when an action occurs.
*/
public void actionPerformed(ActionEvent e);}
public abstract class OutputAction extends ActionListener {
public OutputAction(ProgramInfo programInfo) {
this(programInfo, "出力");
}
public abstract void actionPerformed(ActionEvent e) throws OfsException;
}
上面连个类。。第二给类编译的时候有错。
Multiple ers at this line
- implements java.awt.event.ActionListener.actionPerformed
- Exception OfsException is not compatible with throws clause in
ActionListener.actionPerformed(ActionEvent)
WHY?
这个和JDK升级没有关系,这是基本语法。
子类方法抛出的异常,应该是父类方法跑出异常的子类,或者子类方法不抛出异常。接口中没有跑出异常,子类抛出异常了肯定有问题,还有,接口不是应该用implements吗,LZ用extends编译也能通过?考虑下面的代码,假如:
public class A extends OutputAction{
public static void main(String[] args){
ActionListener listener = new A();
try{
listener.actionPerformed(ActionEvent e);
}catch(OfsException e){
.......
}
}
} OfsException这个异常LZ觉得能捕获到吗?
自定义的是不是RuntimeException取决于你定义的异常继承了什么。