Java Challenge – The Mysterious Method Wrapper

Here is the challenge. Create some Java code so that this JUnit test works:

Basically what I want to do is be able to automatically create wrappers for some object, so that each method with the @Callable can be called with a single common wrapper interface call(). It should be possible to specify the return type via Generics, and the ctor of MethodsToProc should be able to take any type of object.

See if you can do a general solution without cheating! The simpler, the better. You can post code snippets e.g. at snipit or gist. Have fun!

4 Comments on "Java Challenge – The Mysterious Method Wrapper"

Notify of
avatar
Sven Helmberger
Guest

I took some liberties with the implementation because you wanted it simple.

http://snipt.org/TL

Martin Ankerl
Guest

Here is my solution: http://gist.github.com/97038

Sven Helmberger
Guest

I wasn’t so sure about the purpose of having each callable be wrapped in a Proc — seemed like just using the returns values was much simpler (two classes less 😉 but providing the same abilities.

Martin Ankerl
Guest

You are right, your solution is simpler. Using the proc object is probably a bit more flexible, but I have no idea if I ever need that flexibility 🙂

wpDiscuz