Reputation: 41
I'm working on a project which aims to introduce modifications in a code base without directly change the source code, these changes have already been implemented and I am rewriting the code with AspectJ
So far I managed to implement all changes using AspectJ. But I don't know how to implement it:
beforeCadastrarAndValidate ()
which was overridden by a subclass. At the end of this method was inserted the following line: super.beforeCadastrarAndValidate ()
There is a way I can do this?
Thanks!
Upvotes: 4
Views: 228
Reputation: 155
You could call it from the superclass using reflection.
import java.lang.reflect.Method;
class Person {
public void greet() {
System.out.println("Person's greet");
}
}
class Employee extends Person {
public void greet() {
System.out.println("Employee's greet");
}
}
class Main {
public static void main(String[] args)
throws Exception {
// get the method object from Person class.
Method g = Person.class.getMethod("greet",
new Class[0]);
Employee e = new Employee();
// When "g" is invoked on an "Employee" object,
// the "Employee.greet" method is called.
g.invoke(e, null);
}
}
Reference: https://blogs.oracle.com/sundararajan/entry/calling_overriden_superclass_method_on
Upvotes: 1