Method references with types [Re: lambda syntax tutorial]
Rémi Forax
forax at univ-mlv.fr
Fri Aug 6 11:09:55 PDT 2010
Le 06/08/2010 17:40, Paul Benedict a écrit :
> Remi,
>
> That's pretty cool!! Does supporting a conversion to java.lang.reflect
> types make a difference? I still think so because it's part of the
> public api, but what are your thoughts on it?
There are lot of mismatches between method reference and
java.lang.reflect.Method:
java.lang.reflect.Method is a method that is not bound to a peculiar
receiver,
foo#bar() is a method reference which is bound to a receiver (foo).
java.lang.reflect.Method represent a callee, a method that can be called,
foo#bar() is a method reference, a call partially resolved.
(e.g. foo#bar.getAnnotation() has no meaning).
java.lang.reflect.Method checks security at each invocation,
foo#bar checks security once when created.
I let you draw your own conclusion :)
>
> Paul
Rémi
>
> On Fri, Aug 6, 2010 at 10:38 AM, Rémi Forax <forax at univ-mlv.fr
> <mailto:forax at univ-mlv.fr>> wrote:
>
> Le 05/08/2010 23:59, Paul Benedict a écrit :
>> On Thu, Aug 5, 2010 at 4:58 PM, Rémi Forax <forax at univ-mlv.fr
>> <mailto:forax at univ-mlv.fr>> wrote:
>>
>> In fact, it will be something like
>>
>> java.dyn.MethodHandle mh = String#length();
>>
>>
>> Okay, so I would add that too and allow three conversions. I
>> don't think casting to reflected methods/fields should be
>> forgotten. I understand why JSR-292 wants to MethodHandles --
>> that makes sense and I support it. But there is so much code
>> today built around reflection, and being able to cast to those
>> classes would be added value.
>>
>> // automatic SAM conversion
>> Arrays.sortBy(strings, String#length());
>>
>> // automatic reflected method conversion
>> java.lang.reflect.Method m = String#length();
>>
>> // automatic invokedynamic conversion
>> java.dyn.MethodHandle mh = String#length();
>>
>> Paul
>
> Paul,
> there is a secret plan to rewrite java.lang.Method and java.lang.Field
> using MethodHandle to do the plumbing.
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6824466
>
> Rémi
>
>
More information about the lambda-dev
mailing list