As others have already pointed out, you can't get it directly (For example super.super.
doesn't work).
Here is a hack you can mess around with:
try
{
Class<?> s = this.getClass();
while ( !"java.lang.Object".equals(s.getSuperclass().getName()) )
{
s = s.getSuperclass();
}
Method m = s.getMethod(Thread.currentThread().getStackTrace()[1].getMethodName(), (Class<?>[])null);
if ( m != null )
{
m.invoke(s.newInstance()); // This is the actual call to the 'super' method.
}
}
catch ( Exception e )
{
e.printStackTrace();
}
It's not pretty, but for simple classes and methods it works ;)
ps. This hack only supports methods without any parameters. If you need to support parameters you'll need to use the getMethods()
method. Also, if the final "superclass" doesn't support the method it'll also not work, but you can add code in the while loop to check that and catch the last superclass that does support it.