Name of lambda parameters
Remi Forax
forax at univ-mlv.fr
Tue Jan 8 00:14:22 PST 2013
On 01/08/2013 12:16 AM, Tim Peierls wrote:
> On Mon, Jan 7, 2013 at 5:33 PM, Remi Forax <forax at univ-mlv.fr
> <mailto:forax at univ-mlv.fr>> wrote:
>
> On 01/07/2013 07:16 PM, Brian Goetz wrote:
>
> I think this goes into the general bucket of "you can't do
> reflection below the method level in Java", and lambda
> expressions are expressions and therefore below the method
> level. Is lambda somehow special here?
>
>
> Lambda are anonymous functions, so yes, they are special. They can
> be called, have parameters, like methods so reflection should work
> otherwise you can't specify meta-protocol using lambdas and having
> JEE being able to use lambdas seems a good idea.
>
>
> What does "you can't specify meta-protocol using lambdas" mean, and
> why is it a reason to add further complexity?
In JEE context, a meta-protocols is specified usually by adding
annotations classes or methods or method parameters to add dependency
injection, SQL query mapping, JSON mapping, etc.
By example, with lambdas you can write an easy to use API that let you
decode JSON in a 'streamy' way,
If I want to parse:
{
"firstName": "John",
"lastName": "Smith",
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": 10021
},
"phoneNumber": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "fax",
"number": "646 555-4567"
}
]
}
JSONStream stream = ... (outputStream);
stream.parse((String firstName, int age, JSONStream phoneNumber) -> {
System.out.println(firstName + " " + age);
phoneNumber.parse((String type, String number) -> {
System.out.println(number);
}
});
for that, you need a way to do reflection on parameter names (and
annotations).
> --tim
Rémi
More information about the lambda-libs-spec-experts
mailing list