Created
January 17, 2014 11:47
-
-
Save joa/8472165 to your computer and use it in GitHub Desktop.
Calling super method of an instance does not work in Java, unless you call it on the this pointer from within a Class. C++ even allows you to do this: Derived* x = new Derived();
x->Base::meth();
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Base { | |
void meth() { | |
System.out.println("Base::meth"); | |
} | |
} | |
class Derived extends Base { | |
public static void main(String[] args) { | |
Base x = new Derived(); | |
x.meth(); | |
} | |
@Override | |
void meth() { | |
System.out.println("Derived::meth"); | |
Runnable r = new Runnable() { | |
@Override | |
public void run() { | |
Derived.super.meth(); | |
} | |
}; | |
r.run(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment