Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java 8 generic LambdaMetafactory?

While converting Java 8 access private member with lambda? from concrete format to generic format I found another limitation :

To issue a complete symbolic type descriptor, the compiler must also determine the return type. This is based on a cast on the method invocation expression, if there is one, or else Object if the invocation is an expression or else void if the invocation is a statement.

I am curious if there is a way to overcome this?

UPDATE: Working Example per Holger

like image 819
Andrei Pozolotin Avatar asked Mar 03 '26 04:03

Andrei Pozolotin


1 Answers

You can use invoke instead of invokeExact if your compile-time invocation signature does not match the invokedType parameter you have passed to the LambdaMetafactory. It will perform required conversions.

There is no performance penalty regarding the actual invocation of the lambda instance’s method. The decision how the generated lambda will work is made by the LambdaMetafactory before the CallSite encapsulating the MethodHandle is returned. Hence, the way you invoke it to construct the lambda instance does not influence the result.

like image 86
Holger Avatar answered Mar 05 '26 17:03

Holger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!