Fun with method references

Howard Lovatt howard.lovatt at gmail.com
Fri Aug 6 19:13:46 PDT 2010


@Rémi,

> Not a good example, in my opinion.
> using SAM interfaces instead:
>
> interface Foo1 {...}
> interface Foo2 {...}
>
> void foo(Foo1 foo) { ... }
> void foo(Foo2 foo) { ... }

But this is easily resolved with a cast

> interface Handler<A> {
>    public int handle(A a);
> }
>
> void foo(Handler<String> stringHandler) { ... }
> void foo(Handler<Bar> barHandler) { ... }

This is the exactly the same problem that happens with erased function types
and I assume that we don't want is more of these problems. The only way out
of this problem for function types (and generics) is to reify them:

http://www.artima.com/weblogs/viewpost.jsp?thread=278567

  -- Howard.


More information about the lambda-dev mailing list