Java中的异常捕捉是否使用了反射?

Posted by 猪头小队长 | 程序设计 | Tuesday 12 October 2004 16:43

看下面的例子:
public class TestThrowable {

public static void main(String[] args) throws MyAbstractException{
try {
throw (MyAbstractException)new MyException();
} catch (MyException e) {
System.out.println("Caught in main, e.printlnStackTrace()");
}
}
}
class MyAbstractException extends Exception{
}
class MyException extends MyAbstractException{
}

要捕捉MyException类型的异常,却能把MyAbstractException类型的异常捕捉到,这里面看的应该是对象的真正类型,而不是对象的引用所声明的类型

[@more@]

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.