Name of lambda parameters (original) (raw)

Dan Smith daniel.smith at oracle.com
Mon Jan 7 16:28:32 PST 2013


On Jan 7, 2013, at 11:04 AM, Remi Forax <forax at univ-mlv.fr> wrote:

(CC Alex Buckley)

As noticed recently on lambda-dev mailing list, there is no way to get the parameter names of a lambda because there is no way to do reflection on a lambda (an object implementing a functional interface) to get the corresponding declared method.

Note that it is possible to get to the function descriptor:

Method descriptor = lambdaObj.getClass().getInterfaces()[0].getDeclaredMethods()[0]; // horribly oversimplified

What you want, I gather, is to get to the "method" that corresponds to the "lambda object" itself. But note that there need not exist any such method in general.

Block b1 = (String arg1) -> {}; Block b2 = (String arg2) -> {}; assert b1 == b2; // this assertion might succeed

// possible implementation: class EmptyBlock implements Block { void run(String arg3) {} }

Here, what is the "parameter name of" b2?

That fact that the current javac implementation has a one-to-one mapping between lambda expressions and compiled methods is an implementation detail.

(High-level point which is getting muddled here: lambdas are not objects that get converted to functional interface types. Lambdas are expressions that evaluate to instances of functional interfaces.)

—Dan



More information about the lambda-libs-spec-observers mailing list