Created
November 10, 2014 14:02
-
-
Save NickVolynkin/2c467c5e7a1d78a03058 to your computer and use it in GitHub Desktop.
This file contains 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
import java.lang.reflect.Method; | |
/** | |
* @author Nick Volynkin nick.volynkin@gmail.com | |
*/ | |
public class SuperDuperMethodTest { | |
public static void main(String... args) { | |
C c = new C(); | |
c.method2(); | |
} | |
} | |
class A { | |
public void method() { | |
System.out.println("A"); | |
} | |
} | |
class B extends A { | |
@Override | |
public void method() { | |
System.out.println("B"); | |
} | |
} | |
class C extends B { | |
@Override | |
public void method() { | |
System.out.println("C"); | |
} | |
public void method2() { | |
try { | |
Class<?> superDuperClass = this.getClass().getSuperclass().getSuperclass(); | |
System.out.println(superDuperClass); | |
Method method = superDuperClass.getDeclaredMethod("method"); | |
method.invoke(new A()); //A | |
method.invoke(new B()); //B | |
method.invoke(new C()); //C | |
method.invoke(this); //C | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment