Re: why no function types?

Remi Forax forax at univ-mlv.fr
Thu Mar 8 10:08:44 PST 2012


Yes and no.
Using SAM types instead of predefined function types let API developers choose if they want to represent a type of a lambda using a generic type or not.

by example,
  Runnable[] array = { () -> { foo(); } };
is Ok (overdose of parenthesis aside).

Rémi
Sent from my Phone

----- Reply message -----
From: "Neal Gafter" <neal at gafter.com>
To: "maurizio cimadamore" <maurizio.cimadamore at oracle.com>
Cc: <lambda-dev at openjdk.java.net>
Subject: why no function types?
Date: Thu, Mar 8, 2012 17:59


Don't those same limitations apply to function types written in the less
convenient *Mapper<? super A, ? extends B>* style?

On Wed, Mar 7, 2012 at 3:13 PM, maurizio cimadamore <
maurizio.cimadamore at oracle.com> wrote:

> Hi
> Long story short: since function types will probably be implemented as a
> generic type in the compiler generated code (i.e. something like
> Function<A1, A2, ... An, R, E1, E2 ... Em>), function types will be
> subject to the same limitations as generic types because of
> type-erasure; the two most common issues are:
>
> *) cannot write two overloaded methods each one accepting a different
> function type
> *) cannot create an array of function types
>
> Maurizio
>
> On 07-Mar-12 9:48 PM, Antoras wrote:
> > In the archive of the mailing list I found a topic which answers why
> > there are no function types [1].
> >
> > But I don't really understand the reason mentioned there (something
> > about erased function types after type erasure). Therefore I have to ask
> > again. Can someone explain me what happens when we write something like
> >
> > return_value map((A ->  B) f);
> >
> > instead of
> >
> > return_value map(Mapper<A, B>  f);
> >
> > I thought the first one could easily translated to the second one.
> >
> > Thanks in advance
> >
> >
> > [1]:
> >
> http://mail.openjdk.java.net/pipermail/lambda-dev/2011-December/004326.html
> >
>
>
>



More information about the lambda-dev mailing list