J
John N.
I have the following problem in which my program chooses to invoke one
of several competing methods, the chosen one not being the one I want.
Does anyone know whay?
I have:
interface A;
class ASub implements A;
interface B {
foo(A myA);
}
class BSub implements B {
foo(A myA);
foo(ASub myASub);
}
class C {
A myA;
B myB;
C(A myA, B myB) {
this.myA = myA;
this.myB = myB;
}
bar() {
myB.foo(myA);
}
}
main() {
ASub myASub;
BSub myBSub;
C myC = new C(myASub, myBSub);
C.bar();
}
Now, for some reason, bar() invokes BSub.foo(A myA) instead of
BSub.foo(ASub myASub). Can someone explain why? And perhaps suggest a
solution which is elegant (which i realize might involve rethinking
everything).
Thanks.
John
of several competing methods, the chosen one not being the one I want.
Does anyone know whay?
I have:
interface A;
class ASub implements A;
interface B {
foo(A myA);
}
class BSub implements B {
foo(A myA);
foo(ASub myASub);
}
class C {
A myA;
B myB;
C(A myA, B myB) {
this.myA = myA;
this.myB = myB;
}
bar() {
myB.foo(myA);
}
}
main() {
ASub myASub;
BSub myBSub;
C myC = new C(myASub, myBSub);
C.bar();
}
Now, for some reason, bar() invokes BSub.foo(A myA) instead of
BSub.foo(ASub myASub). Can someone explain why? And perhaps suggest a
solution which is elegant (which i realize might involve rethinking
everything).
Thanks.
John