Late binding for lamba parameters?
Brian Goetz
brian.goetz at oracle.com
Fri Sep 13 11:17:09 PDT 2013
Java does a lot of things dynamically, but one thing it does completely
statically is method selection. You get static overload selection,
dynamic dispatch on the receiver, and static dispatch on the other
arguments.
On 9/13/2013 5:41 AM, Millies, Sebastian wrote:
> Hello there,
>
> as Project Lambda has introduced some elements of laziness into Java, I
> wondered about the following question:
> Is it possible to have methods in a lambda body dispatch on an argument type
> determined at run time? Or in otherwords, can the type inference for the
> lambda parameter be delayed by using some sort of type variable?
>
> Example:
>
> class AbstractElem {}
> class ConcreteElem1 extends AbstractElem {}
> class ConcreteElem2 extends AbstractElem {}
>
> void process() {
> List<? extends AbstractElem> list = new ArrayList<>();
> list.forEach( e -> processConcreteElem(e) );
> }
>
> void processConcreteElem(ConcreteElem1 e) {...}
> void processConcreteElem(ConcreteElem2 e) {...}
>
> This would be really useful, not having to do double-dispatch through the
> Visitor pattern, but it seems it's still impossible, right? Has this been discussed
> at all?
>
>
> n Sebastian
>
> Software AG - Sitz/Registered office: Uhlandstra?e 12, 64297 Darmstadt, Germany - Registergericht/Commercial register: Darmstadt HRB 1562 - Vorstand/Management Board: Karl-Heinz Streibich (Vorsitzender/Chairman), Dr. Wolfram Jost, Arnd Zinnhardt; - Aufsichtsratsvorsitzender/Chairman of the Supervisory Board: Dr. Andreas Bereczky - http://www.softwareag.com
>
>
More information about the lambda-dev
mailing list