Reputation: 937
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
Upvotes: 3
Views: 808
Reputation: 298103
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.
Upvotes: 4