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)?
but for Eclipse instead of Visual Studio. Both NetBeans and Eclipse have a function that, if you declare a Java class to implement an interface but omit one or more methods, will automatically generate a stub method for you. The difference is that the Eclipse version will do nothing, and return zero or null, e.g.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With