Skip to content

Instantly share code, notes, and snippets.

@joa
Created January 17, 2014 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joa/8472165 to your computer and use it in GitHub Desktop.
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();
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