Function types versus arrays
forax at univ-mlv.fr
Mon Feb 8 02:17:56 PST 2010
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);
> 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);
Object array = arrayOfFunction;
array = #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
for an array of function type (#String(String)) illegal.
I'm also happy with List, perhaps we should introduce a new interface
which is a super type of List and array of objects but that another story.
More information about the lambda-dev