多个基类定义的同一个方法的异常交集

public class Type3 implements Type1, Type2 {
	public void f() {
		System.out.println("do not need throws any Exception");
	}

	public static void main(String[] args) {
		Type3 tp = new Type3();
		tp.f();
	}
}
interface Type1 {
	void f() throws CloneNotSupportedException;
}
interface Type2 {
	void f() throws InterruptedException;
}

 输出为:

do not need throws any Exception

    一个方法可以抛出的被检查异常集合是它所适用的所有类型声明要抛出的被检查异常集合的交集,

    而不是合集。

猜你喜欢

转载自jaesonchen.iteye.com/blog/2288207