在以下代碼:矛盾例外規格相同的方法在不同的接口
class MyException extends Exception{}
interface Bread
{
public void eat() throws MyException;
}
interface Fringe
{
public void eat() throws RuntimeException;
}
public class Test implements Fringe , Bread // #5
{
public static void main(String[] args)
{
Fringe best = new Test(); // #1
best.eat();// #2
}
public void eat() throws RuntimeException // #3
{
System.out.println("Test");
throw new RuntimeException(); // #4
}
}
MyException
不是RuntimeException
。爲什麼我們可以宣佈Test.eat()
投擲RuntimeException
,但不是一般的Exception
?
確定您要檢舉的內容? MyException實際上並沒有在這裏的任何地方拋出。 – cha0site 2012-01-18 12:08:09