What is the type of a "method reference"?

Behrooz Nobakht nobeh5 at gmail.com
Thu Jun 13 12:52:20 PDT 2013


Thanks for the link which was quite insightful. Still, I'm wondering about
the following. I'd like to be able to do the following in Java 8:

   - Have a method declaration such as doSomething(Function<?, ?> f,
   Object... args) in some class. I should use Function, right?
   - And then, be able to use a "method reference" to pass into
doSomethingsuch as doSomething(SomeClass::someMethod,
   p1, p2)
   - The idea is to execute a method reference with "indirection"; i.e.
   "apply" the method reference to the arguments.

Is this possible in Java 8? How?

If not, any suggestion to approach it? Such as MethodHandle?

Thanks again!
Behrooz


On Wed, Jun 12, 2013 at 11:12 AM, Remi Forax <forax at univ-mlv.fr> wrote:

> On 06/12/2013 10:35 AM, Behrooz Nobakht wrote:
>
>> Thanks for the reply. Just a follow-up question regarding the fact that
>> method references *do not* have a type:
>>
>> When a Java 8 method reference is compiled, what is it translated to? Is
>> there any specific place in the source of Java 8 I can look up to study
>> this particular question in more details?
>>
>
> There is this document from last year,
> http://cr.openjdk.java.net/~**briangoetz/lambda/lambda-**translation.html<http://cr.openjdk.java.net/~briangoetz/lambda/lambda-translation.html>
>
> It's not fully accurate, but the first half of the doc is not too outdated.
>
> cheers,
> Rémi
>
>
>
>>
>>
>>
>> On Wed, Jun 12, 2013 at 10:22 AM, Florian Weimer <fweimer at redhat.com>
>> wrote:
>>
>>  On 06/11/2013 11:50 PM, Behrooz Nobakht wrote:
>>>
>>>  My question is that how should the method doAnotherThing be declared?
>>>>
>>>>  In most cases, it is appropriate to define an interface with a single
>>> method and use it as a parameter type.
>>>
>>>
>>>   Studying the source code of Java 8, I found out that before Java 8
>>> version
>>>
>>>> b75, there was an abstraction java.util.function.Block which was removed
>>>> from further revisions.
>>>>
>>>>  There is java.util.function.Function, but it's probably most useful in
>>> abstract contexts where no reasonably named concrete type is available.
>>>
>>> On the question in the subject, method references do not have a type.
>>>
>>> --
>>> Florian Weimer / Red Hat Product Security Team
>>>
>>>
>>
>>
>


-- 
-- Behrooz Nobakht


More information about the jdk8-dev mailing list