Reputation: 163
I have a about 100 calls of external methods from my own code.
Now I try to perform some actions before and after one of those methods is called.
Is there a way to define a method with an argument containing an other method/block of code, that should be performed? I know this would be highly risky, but overloading 100 of methods within a code I'm not able to edit is also no fun.
Any help would be appreciated
Thanks
Upvotes: 0
Views: 72
Reputation: 163
todo(System.out.println("t"));
public void todo(String a){
runtime.exec(a);
}
Upvotes: 0
Reputation: 121760
Is there a way to define a method with an argument containing an other command that should be performed?
Well, yes. For instance:
public interface Command
{
void doSomething();
}
then you could call your method with an argument of type Command
. All you "have to do" is provide implementations of this interface. For instance:
public void doCommand(final Command command)
{
command.doSomething();
}
Upvotes: 0