- interface I1{
- void f();
- }
- interface I2{
- int f(int i);
- }
- interface I3{
- int f();
- }
- class C{
- public int f(){
- return 1;
- }
- }
- class C2 implements I1,I2{
- public void f(){ }
- public int f(int i){
- return 2;
- }
- }
- class C3 extends C implements I2{
- @Override
- public int f(int i) {
- return 3;
- }
-
- }
- class C4 extends C implements I3{
- public int f(){
- return 4;
- }
- }
- //The return types are incompatible for the inherited methods I1.f(), C.f()
- //class C5 extends C implements I1{ }
- //The return types are incompatible for the inherited methods I1.f(), I3.f()
- //interface I4 extends I1, I3{ }
复制代码 就结果而言,子类会从继承和实现的方法中取得一个交集,交集中必须避免“方法签名相同但返回值不同”的情况。
|
|