What is the type of a "method reference"?

Behrooz Nobakht nobeh5 at gmail.com
Tue Jun 11 14:50:07 PDT 2013


Hi,

I have a question regarding the method references in Java 8. Let's say that
I have a class:

class MyClass {
    Object doSomething(Object o);
}

And, I'm using the method reference MyClass::doSomething in a call
such as SomeOtherClass.doAnotherThing(p,
MyClass::doSomething). In this call, let's assume that p is an arbitrary
parameter and doAnotherThing method knows how to provide the parameter for
doSomething.

My question is that how should the method doAnotherThing be declared?

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.

So, maybe, another question is that since Block is not available what is
its best replacement in the current version of Java 8? What is the
top-level abstraction that represents a block of code such as a method
reference? Or, in other words, if using lambdas, what is the type that
could replace a lambda in method definitions?

Having Block allowed to use define methods with parameters that are as
general as a block of code (a method reference). Now, what should be used
instead?

I would appreciate your answers and explanations.

Best,
Behrooz


More information about the jdk8-dev mailing list