Skip to content
Advertisement

Java access bean methods with LambdaMetafactory

my question is strongly related to Explicit use of LambdaMetafactory in that thread, some very good examples are provided to use the LambdaMetafactory to access a static method of a class; however, I wonder what is the equivalent code to access a non static field of an existing bean instance. It seems really hard to find an example and every attempt I performed ended up in non working code.

This is the bean code:

JavaScript

Here a working unit test that successfully access the static method “getStaticObj()”:

JavaScript

Now here my failing attempts to access the non static “getObj()” method:

JavaScript

Every attempt has a different negative result, I really hope someone is abe to help me to have at least one test working fine.

Advertisement

Answer

If you want to bind values to your lamba, you have to include these parameters to the invokedtype signature:

JavaScript

Instead of binding a value you may use a Function which takes the bean as argument:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement