[Java.Interop] Avoid some method group conversions #1050
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context: https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-11#improved-method-group-conversion-to-delegate Context: #1034 Context: dotnet/roslyn#62832
C#11 introduced a "slight semantic" change with "Improved method group conversion to delegate":
The result of optimization is that for current
generator-emitted code such as:The
(_JniMarshal_PP_V) n_Fooexpression is a "method group conversion", and under C#11 the generated IL is larger, as the delegate instance is cached in case it is needed again.However in our case we know the delegate instance won't be needed again, not in this scope, so all this "optimization" does for us is increase the size of our binding assemblies when built under C#11.
Review
src/Java.Interopfor use ofnew JniNativeMethodRegistrationand replace "cast-style" method group conversions(D) Mto "new-style" delegate conversionsnew D(M). This explicitly "opts-out" of the C#11 optimization.