A syntax option (function types versus arrays)

Alex Blewitt alex.blewitt at gmail.com
Thu Mar 11 01:07:40 PST 2010


On 11 Mar 2010, at 08:30, Gernot Neppert wrote:

>>> I like the following two things about this syntax:
>>> 
>>> firstly, the use of "new" to create a lambda. This makes it consistent
>>> with other object instantiations (in this case, an object of function
>>> type being created).
>> 
>> However, it precludes the compiler from being able to optimise out instance creation in the case that the lambda is constant (or doesn't capture/use local state) since 'new' is defined semantically and by general understanding to create a new instance every time.
> 
> Of course, if you intend to make lambda creation special with regards
> to automatic instance caching by the compiler, using 'new' is not a
> good idea. OTOH, is this really necessary?
> I have confidence that the capable library developer will identify
> stateless, non-capturing lambdas herself and provide factories for
> them or store them in static fields.

This is essential, yes. The majority of 'capable library developers' may not, but the majority of Java developers using lambdas for the first time may well do so. You'd like the compiler to do that for you. 

Alex


More information about the lambda-dev mailing list