In Java, suppose I have 3 classes, C extends from B, which extends from A.
class X {
interface A {}
interface B extends A {}
interface C extends B {}
void f(A a) {}
void test() {
C c = new C()
B b = (B) c;
f(b);
}
}
If I do something like this, as shown in the test()above:
C c = new C()
B b = (B) c;
f(b);
f()It receives bas type C, as C, and bthe two extend from A. I wanted to f()get bas a type b, not a type C.
Is there any way to make this increase?
simao source
share