Function types versus arrays

Neal Gafter neal at gafter.com
Mon Feb 8 07:48:45 PST 2010


If arrays of functions are illegal, then the function-type syntax

#(Types Throws_opt)->Type

(which was previously rejected because there was no way to write an
array of function type) can be reconsidered.

On Mon, Feb 8, 2010 at 2:17 AM, Rémi Forax <forax at univ-mlv.fr> wrote:
> Le 07/02/2010 19:41, Neal Gafter a écrit :
>> I've been asked if arrays and function types will play nicely
>> together.  Specifically, for example, whether or not something like
>> the following will be allowed:
>>
>> #String(String)[] arrayOfFunction = new #String(String)[10];
>>
>> The current draft spec, by the absence of any constraining rules,
>> implies yes.  But if I have to guess, I would say the end result of
>> project lambda will probably say no.  Although we haven't talked much
>> about implementation techniques, I'm not aware of any proposed
>> implementation technique that would allow this without opening a hole
>> in the type system.
>>
>> I don't know whether we should consider this important or not (I
>> don't; I'm perfectly happy using java.util.List), but if it is
>> important then someone should be thinking about what needs to happen
>> (VM support?) to make it work.
>>
>
> For the record the problem is:
>
> #String(String)[] arrayOfFunction = new #String(String)[10];
> Object[] array = arrayOfFunction;
> array[0] = #int() (2);
>
> The last line should raise an array store exception.
> So the VM should be aware of the precise type of the array of function.
>
> Currently, neither the anonymous class translation nor the method handle one
> provide reified function type so array of function types are unsafe.
>
> Because function type doesn't exist in the language, I propose to make
> the syntax
> for an array of function type (#String(String)[]) illegal.
>
> I'm also happy with List, perhaps we should introduce a new interface
> ReadOnlyList
> which is a super type of List and array of objects but that another story.
>
>> Cheers,
>> Neal
>>
>
> Rémi
>
>


More information about the lambda-dev mailing list