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
一个方法可以抛出的被检查异常集合是它所适用的所有类型声明要抛出的被检查异常集合的交集,
而不是合集。
本文探讨了Java中一个类实现多个接口时如何处理不同接口声明的异常问题,并通过示例代码展示了当这些接口声明的方法签名相同时,该类方法实际抛出的异常是由所有接口声明异常的交集决定的情况。
664

被折叠的 条评论
为什么被折叠?



