python做网站部署,wordpress修改页尾,奥门网站建设,做网站怎么接广告赚钱吗前段时间读一些代码#xff0c;其中包含了若干复杂的implemens和extends关系#xff0c;居然在调用时出现了the method *** is ambiguous for the type *** . 一直以为java中没有多继承#xff0c;正常的多态怎么会造成这种问题。请看下面的场景#xff1a;public class Am…前段时间读一些代码其中包含了若干复杂的implemens和extends关系居然在调用时出现了the method *** is ambiguous for the type *** . 一直以为java中没有多继承正常的多态怎么会造成这种问题。请看下面的场景public class AmbiguousExpector {class A {}class B extends A implements IC{}interface IC {}void test(A a){}void test(IC b){}void ambiguous(){B b new B();test(b);}}上述代码无法编译The method test(AmbiguousExpector.A) is ambiguous for the type AmbiguousExpector AmbiguousExpector.javaline 20 Java Problem。原因B extends A的同时implements IC,但是在Class AmbiguousExpector 中的test方法签名中接受参数为A 或者 IC不幸的是变量b此时既满足test(A a)又满足Test(IC b),所以产生了ambiguous的错误。可以尝试注释掉任意一个test方法编译都可以通过。或者增加test(B b).上述错误当使用generic的时候可以扩展如下public class AmbiguousExpector {class A {}class B extends A implements IC{}interface IC {} void test(T a){}void test(V b){}// void test(A a){}// void test(IC b){}void ambiguous(){B a new B();test(a);}}结果一样。