0
有人可以解釋爲什麼第一個演員不給CCE?Java異常。將其中一個類型投射到另一個類型
public class Test {
public static void main(String[] args) throws Throwable {
Test.<RuntimeException>throwIt(new Exception());
}
@SuppressWarnings("unchecked")
private static <T extends Throwable> void throwIt(Throwable throwable) throws T {
throw (T) throwable; // no ClassCastException
throw (RuntimeException) throwable; // ClassCastException(as it should be)
}
}
P.S.評論一個演員(否則它不會編譯)。
第二'throw'不可達 – Reimeus 2013-02-27 11:38:27
什麼是你的問題?你的代碼是否編譯?您將收到無法訪問的代碼編譯錯誤。 – Jayamohan 2013-02-27 11:38:45
哦,常見,然後評論其他 – Bax 2013-02-27 11:39:02