Method calls vs lambda calls
Howard Lovatt
howard.lovatt at iee.org
Tue Dec 15 07:11:32 PST 2009
I remain to be convinced that method references are a good idea, since
they pull Java much further towards structural typing than at present
and this will be very confusing for people to be presented with two
type systems.
That desirability point aside, the technical issue of what name space
a function type should be in can be resolved by putting a function
type in both the method and the field/variable name spaces. You need
to do this because it is used both as a field/variable:
#int() fortyTwo = #() (42); // declare and assign to the field/variable
or
out.println( fortyTwo ); // prints something like Function_int at 0xXXXX
and as a function:
out.println( fortyTwo() ); // prints 42
Normal Java rules apply in all cases, if function types are in both
name spaces, since you can always tell if it is a function call or a
field reference.
Actually there are still some rough edges since methods are
dynamically resolved and fields aren't. You can paper over this
difference a little by saying that function types can't be hidden.
However, people might find this difference, can't hide, confusing.
Mark Thornton wrote:
>>
>>
> A simple solution would be to specify that method valued fields are in
> the method namespace. Your example would then not compile. I think this
> would be preferable to having different syntax to discriminate between
> the method call and invoking a field.
>
> Mark Thornton
More information about the lambda-dev
mailing list