I’m extending a class and overriding a method. All I want to do is to call super, but with a modified argument that gets intercepted upon one of its methods is called. An example makes it more clear:
// Foo is an interface and also this method is part of an interface
@Override
public void foo(Foo foo) {
// I want to intercept the call to foo.bar() in super
super.foo(foo);
}
I’d rather use a tool that doesn’t require a compiler of its own. What would be the optimal one?
Given that
Foois an interface, you might consider using a dynamic proxy that would:There is a complete example in the above link. Here is just the idea:
Note that if
Foowas not an interface, you could still subclassFooand override all methods manually so as to forward them.It’s pseudo-code, and I haven’t tested it. In both cases, the wrapper allows you to intercept a call in
super.Of course, the wrapper has not the same class as the original
Foo, so if super usesinstanceof, then it might be problematic.
Hope that I understood your problem right and that it helps.