Late binding for lamba parameters?

Millies, Sebastian Sebastian.Millies at
Fri Sep 13 02:41:39 PDT 2013

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?


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 -

More information about the lambda-dev mailing list