[ 
https://issues.apache.org/jira/browse/GROOVY-11363?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Paul King updated GROOVY-11363:
-------------------------------
    Description: 
This code:
{code}
import groovy.transform.CompileStatic
import java.util.function.Supplier

@CompileStatic
Supplier<String> method() {
    5::toString
}

method().get()
{code}
Fails with this error:
{noformat}
java.lang.BootstrapMethodError: bootstrap method initialization exception
        at 
java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:188)
        at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:315)
        at 
java.base/java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:281)
        at 
java.base/java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:271)
        at ConsoleScript9.method(ConsoleScript9:6)
        ...
Caused by: java.lang.invoke.LambdaConversionException: Type mismatch in 
captured lambda parameter 0: expecting int, found class java.lang.Object
{noformat}

My initial expectation is that the wrapper type/boxed version should be used.

See also:
https://stackoverflow.com/questions/78369048/groovy3-how-to-get-java-lambdas-instead-of-closures

  was:
This code:
{code}
import groovy.transform.CompileStatic
import java.util.function.Supplier

@CompileStatic
Supplier<String> method() {
  5::toString
}

method().get()
{code}
Fails with this error:
{noformat}
java.lang.BootstrapMethodError: bootstrap method initialization exception
        at 
java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:188)
        at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:315)
        at 
java.base/java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:281)
        at 
java.base/java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:271)
        at ConsoleScript9.method(ConsoleScript9:6)
        ...
Caused by: java.lang.invoke.LambdaConversionException: Type mismatch in 
captured lambda parameter 0: expecting int, found class java.lang.Object
{noformat}

My initial expectation is that the wrapper type/boxed version should be used.


> Bootstrap method error for method reference used with a primitive literal
> -------------------------------------------------------------------------
>
>                 Key: GROOVY-11363
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11363
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 5.0.0-alpha-8, 4.0.21
>            Reporter: Paul King
>            Priority: Major
>
> This code:
> {code}
> import groovy.transform.CompileStatic
> import java.util.function.Supplier
> @CompileStatic
> Supplier<String> method() {
>     5::toString
> }
> method().get()
> {code}
> Fails with this error:
> {noformat}
> java.lang.BootstrapMethodError: bootstrap method initialization exception
>       at 
> java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:188)
>       at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:315)
>       at 
> java.base/java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:281)
>       at 
> java.base/java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:271)
>       at ConsoleScript9.method(ConsoleScript9:6)
>         ...
> Caused by: java.lang.invoke.LambdaConversionException: Type mismatch in 
> captured lambda parameter 0: expecting int, found class java.lang.Object
> {noformat}
> My initial expectation is that the wrapper type/boxed version should be used.
> See also:
> https://stackoverflow.com/questions/78369048/groovy3-how-to-get-java-lambdas-instead-of-closures



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to