Hi All,
I wish to to if there is any way by which we can access a method of the
Super Base class. (We can not modify base class and super base class
and the method to be accessed has been overridden in both the classes.)
Thanks a lot
Mohit Garg
hardik - 18 Apr 2006 05:59 GMT
when u call mathod u can use super keyword before accessing super class
mathod.
like super.<mathodname>
may be it will work for u.
Piotr Kobzda - 18 Apr 2006 21:56 GMT
> I wish to to if there is any way by which we can access a method of the
> Super Base class. (We can not modify base class and super base class
> and the method to be accessed has been overridden in both the classes.)
The way to achieve this is a transformation of your bytecode to the one
using old 'invokespecial' instruction semantics.
Use the following example as a guide to the solution:
class A {
void m() {}
}
class B extends A {
void m() {}
}
class C extends B { // unset ACC_SUPER flag of the class
void m() {
((A)this).m(); // replace 'invokevirtual' with 'invokespecial'
}
}
The problem with that is I'm not sure all JVMs must support it...
Regards,
piotr
Chris Uppal - 19 Apr 2006 09:14 GMT
> I wish to to if there is any way by which we can access a method of the
> Super Base class. (We can not modify base class and super base class
> and the method to be accessed has been overridden in both the classes.)
You can't do it in Java.
As Piotr has mentioned, there is a (very) old semantics for bytecode which
might allow you to hand-generate non-standard bytecodes to do that. Also, it
can certainly be done via JNI (CallNonVirtualXxxMethod()). But the bottom line
is that if you need to do that then your design is fundamentally broken. (Or,
in this case, it may be that the design of the classes you have inherited is
broken.)
-- chris