Java and skipping level with super

Possible duplicate:
Why super .super.method (); not allowed in java?

If you have a class that comes from a class that comes from another, is there any way for me to call the super.super method, and not the overridden one?

class A{ public void some(){} } class B extends A{ public void some(){} } class C extends B{ public void some(){I want to call A.some();} } 
+4
source share
2 answers

@tgamblin is right, but here is a workaround:

 class A{ public void some(){ sharedCode() } public final void someFromSuper(){ sharedCode() } private void sharedCode() { //code in A.some() } } class B extends A{ @Override public void some(){} } class C extends B{ @Override public void some(){ //I want to call A.some(); someFromSuper(); } } 

Create a second version of your method in A that is final (not redefined) and will call it from C.

This is a really bad design, but sometimes it is needed and used inside the JDK itself.

Regards, StΓ©phane

+3
source

All Articles