0

With lambdaj I can do something like this to get the name of a property in a refactoring-safe way.

import static ch.lambdaj.Lambda.on;
import static ch.lambdaj.function.argument.ArgumentsFactory.actualArgument;

...

actualArgument(on(User.class).getUsername()).getInkvokedPropertyName();

How can I do that in Java 8 without lambdaj?

baymon
  • 459
  • 1
  • 5
  • 20
  • Just to clarify for those not using lambdaj, what does the code do? Can you give examples? – Tunaki Jun 01 '16 at 18:49
  • 3
    Is “inkvoked” supposed to mean “invoked”? Damn compatibility restrictions that force us to maintain typos… Nevertheless, if you expect to get back the string `"username"`, that’s not supported. Java 8’s method references and lambda expressions are ordinary, non-Reflective code. As you can’t find out what a conventional `Function` implementation does, you can’t find out in case the `Function` is implemented via, e.g. `User::getUsername`. It’s supposed to make no difference to whoever uses the `Function` instance. – Holger Jun 01 '16 at 18:55
  • 1
    To be complete, [here](http://stackoverflow.com/q/21860875/2711488) is a discussion about a limited possibility that may be useful during debugging, but as a general tool, e.g. for just getting “refactoring-safe” property names, it’s strongly discouraged. – Holger Jun 01 '16 at 19:06

0 Answers0