I have to create several proxies, to add, for example, logging. Something like that:
interface IMath {
public int add(a, b);
}
class Math implements IMath {
public int add(a, b) { return a + b; }
}
class MathWithLogs implements IMath {
private IMath realMath;
public int add(a, b) {
Log.d("tag", "valueable info");
return realMath.add(a, b);
}
}
Everything is fine as long as these interfaces aren’t 20 methods and I have to add something to just one.
My question is, is there a way to autogenerate wrapper classes with some plugin for eclipse?
Or maybe there is a way to do something with annotations to invoke methods from realMath unless stated otherwise (like @Override)?
Right click in any source file (.java) and navigate to
source -> Override/Implement Methods/Generate Delegate Methods.The first will paste the body of all methods of your immediate interface.
the second will do the same for all the hierarchy up to Object(I guess, not sure).
Hope this helps.