Function types versus arrays

Greg Dennis gdennis at alum.mit.edu
Wed Feb 17 19:22:28 PST 2010


Ignorant question from a lurker ...

Would it be possible to reify just those function types that don't
have generics in their type signature? If this were the case, would
that allow arrays of functions so long as the functions do not have
generics in their signature? I would consider that consistent with the
existing restriction against arrays of generics.


> Date: Wed, 17 Feb 2010 18:18:39 -0800
> From: Neal Gafter <neal at gafter.com>
> Subject: Re: Function types versus arrays
> To: Joshua Bloch <jjb at google.com>
> Cc: lambda-dev <lambda-dev at openjdk.java.net>
> Message-ID:
>        <15e8b9d21002171818j69b3f6a4s141b1af8fb75de78 at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> On Wed, Feb 17, 2010 at 5:59 PM, Joshua Bloch <jjb at google.com> wrote:
>> Can you provide a concise proof that it would require reifying generics? ?It
>> isn't obvious (to me).
>
> Sure.  If you need more formality, I can work on it this weekend.  One
> form of proof goes something like this:
>
> Consider some an existing generic method.  We assume that the existing
> callers of this method do not pass enough information for the body of
> the method to know, at runtime, the actual types of the type
> parameters.  (If needed, I can prove this assumption.)  Now add a
> lambda expression inside the body of the method, with the type
> parameter appearing in its signature.  The JLS says that changes to
> the body of a method are binary compatible.  If function types are
> reified, then the type of this lambda expression is available at
> runtime.  But that contradicts our assumption that existing callers of
> the method do not pass enough information to reify the type parameter.
>
> You might imagine addressing this by disallowing lambdas with type
> parameters in their signature, but this would prevent lots of code
> (for example, the parallel arrays implementation) from using lambdas.
> Lambda expressions are the only way to create values of function type;
> anonymous inner classes are not an implementation alternative.
> Therefore, the restriction would prevent the parallel arrays API from
> using function types.
>
> -Neal


More information about the lambda-dev mailing list