I have two classes:
public class A {
public Object method() {...}
}
public class B extends A {
@Override
public Object method() {...}
}
I have an instance of B
. How do I call A.method()
from b
? Basically, the same effect as calling super.method()
from B
.
B b = new B();
Class<?> superclass = b.getClass().getSuperclass();
Method method = superclass.getMethod("method", ArrayUtils.EMPTY_CLASS_ARRAY);
Object value = method.invoke(obj, ArrayUtils.EMPTY_OBJECT_ARRAY);
But the above code will still invoke B.method()
.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…