A syntax option (function types versus arrays)
Gernot Neppert
mcnepp02 at googlemail.com
Thu Mar 11 00:30:54 PST 2010
>> 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 (akin to
String.CASE_INSENSITIVE_COMPARE):
lambda<Iterable<Integer>,Iterable<Integer>> even = IntegerFilters.EVEN;
More information about the lambda-dev
mailing list