Wanted: overloading use cases

Dan Smith daniel.smith at oracle.com
Wed Oct 10 15:48:15 PDT 2012

I've recently been exploring and refining our overload resolution algorithm for Lambda.  I'm looking for some real-world examples of Lambda code that we should support.  If you have experience with a library that makes use of lambda-like features (in any language, or a Java library that could naturally be enhanced with lambda support), please read on!

A typical challenging use case for overload resolution looks like this:

interface Stream<E> {
 <R> Stream<R> map(Mapper<E, R> m);
 IntStream map(IntMapper<E> m);
 LongStream map(LongMapper<E> m);

Stream<Foo> s = ...;
s.map(f -> f.method());

Notable properties of this example:
1) There are multiple methods of the same arity, differing in a functional interface parameter type
2) The arities of the corresponding functional interfaces are identical
3) No non-lambda argument can be used for disambiguation
4) The functional interfaces have the same parameter type(s)

(Also interesting, but not so relevant to this discussion: the lambda may be compatible with multiple functional interfaces, leaving us to pick a best match after throwing out the incompatible candidates.)

1-3 push the required complexity of our approach (assuming we want to support this use case).  4 limits the complexity.

I'm searching for real-world examples that illustrate 1-3, but that do _not_ have 4 as a simplifying property.  Here's what this might look like:

void poke(Predicate<String> p);
void poke(Mapper<Foo, String> m);

poke(x -> x.isEmpty());

If you can think of something like this in any real library that you're familiar with, I'd love to hear about it.  (Of course, some languages have very different approaches to overloading.  The idea is to identify APIs that a person could map to Java code that fits the above description, and have a reasonable expectation of smooth interaction with implicitly-typed lambdas.)

I've done some exploring of my own in C# (LINQ) and Scala (standard libraries) and, surprisingly, have turned up very few cases at this level of complexity.  My hope is that the diversity of experience of interested community members will help to cast a broader net.


More information about the lambda-dev mailing list