Multi-dimensional array creation references

Brian Goetz brian.goetz at oracle.com
Wed May 8 10:20:14 PDT 2013


I'm fine with the current treatment, certainly for now.

On 5/8/2013 12:10 PM, Dan Smith wrote:
> We currently have array creation references:
>
> Function<Integer,String[]> f = String[]::new;
>
> Which are shorthand for lambdas that contain array creation expressions:
>
> Function<Integer,String[]> f = i -> new String[i];
>
> The array type may be a multi-dimensional array, and the integer represents the outermost dimension:
>
> Function<Integer,String[][]> f = String[][]::new;
> Function<Integer,String[][]> f = i -> new String[i][];
>
> We do not support _multiple_ integer parameters:
>
> BiFunction<Integer,Integer,String[][]> f = String[][]::new; // illegal
> BiFunction<Integer,Integer,String[][]> f = (i,j) -> new String[i][j];
>
> This was raised on lambda-dev as something to consider supporting.  I don't have a strong opinion one way or another; I don't think it's essential, and I don't think this is a particularly common use case, but it also wouldn't be too hard to do.  It does  carry a small amount of extra complexity.
>
> Does anyone have an opinion?
>
> I had this to say on lambda-dev:
>
>> Method references are essentially shorthand for lambda expressions.  We've selected a few common forms of lambda expressions to give them special treatment.  But there will always be something just slightly different that lives outside of the set we've chosen to support.  And in that case, the solution is to use a lambda expression instead.
>
> —Dan
>


More information about the lambda-spec-observers mailing list