Hey, I'm working on a functional library for Java. If any of you are familiar with the STL in C++, you may know about the algorithm and the functional libraries. I am basically trying to do the same with Java, a type safe way to be able to pass functions objects of certain parameters along. Unlike the reflection, these function objects are lightweight and can be called with little overhead.
There is already an existing library out that does this, but their function objects only support a certain number of parameters per type, and each type does not share a super-interface. This one does, allowing universal extensible functionality.
I am even providing functionality like bind1st, bind2nd, bind, for_each, and many other meta-programming constructs that can use these functions, like in C++.
Now in C++, the behind the scenes template meta-programming stuff gets REALLY convoluted, and its a similar situation here. Worse, unlike C++, Java's generics cannot be "overloaded", and a proper compile time generic signature of an arbitrary number of arguments cannot be automatically generated . This makes the general case very messy, and on a few occasions type safety will not be possible. For instance, the bind() method (the ultra-flexible one) cannot be made in a universally typesafe way in Java.
Now, of course, the end programmer needs not worry about all this stuff. There are much simpler interfaces and abstract classes which take care of the worst for you.
Now why would you want to use this? Many good intermediate to advanced C++ books talk about the <algorithm> and the <tr1/functional> (or possibly <functional> on certain platforms) libraries and why its a good idea to use them. Basically, there are some really clever for_each, et al, implementations that use clever optimizations (like smart loop-unrolling) or even parallelization, and you don't have to know about any of it to take advantage of it. Plus, it can turn an ugly multiline for loop into a single line of code of a few function calls.
If you think I should post this on Google code or something, or if you want any nifty examples about how this can shrink several lines into one, feel free to ask.
Whew, that was a long post.