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
一个方法可以抛出的被检查异常集合是它所适用的所有类型声明要抛出的被检查异常集合的交集,
而不是合集。