You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Felix Schnabel (Jira)" <ji...@apache.org> on 2022/11/06 15:51:00 UTC
[jira] [Comment Edited] (GROOVY-10813) Cannot create method reference for print or println
[ https://issues.apache.org/jira/browse/GROOVY-10813?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17629498#comment-17629498 ]
Felix Schnabel edited comment on GROOVY-10813 at 11/6/22 3:50 PM:
------------------------------------------------------------------
So for the lambda and the NPE:
The NPE happens, because the lambda you specified has no typeinformation for it's argument.
Following example works for me:
{code:groovy}
@groovy.transform.CompileStatic
void testClosure(){
java.util.function.Consumer c = (Object x) -> print(x)
c.accept('hello world!')
}
testClosure()
{code}
was (Author: JIRAUSER295331):
So for the lambda and the NPE:
The NPE happens, because the lambda you specified has no typeinformation for it's argument.
Following example works for me:
```
@groovy.transform.CompileStatic
void testClosure(){
java.util.function.Consumer c = (Object x) -> print(x)
c.accept('hello world!')
}
testClosure()
```
> Cannot create method reference for print or println
> ---------------------------------------------------
>
> Key: GROOVY-10813
> URL: https://issues.apache.org/jira/browse/GROOVY-10813
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation
> Affects Versions: 3.0.13, 4.0.6
> Reporter: Eric Milles
> Priority: Major
>
> Consider the following:
> {code:groovy}
> @groovy.transform.CompileStatic
> void p() {
> java.util.function.Consumer c = this::print
> c.accept('hello world!')
> }
> p()
> {code}
> Throws error "LambdaConversionException: Type mismatch in captured lambda parameter 0: expecting class _script_, found class java.lang.Object"
> I was trying to print a stream element via "this::println". This fails also with "System.out::println" as well. I had to use closure syntax which works just fine. Lambda throws NPE: "Consumer c = obj -> print(obj)"
--
This message was sent by Atlassian Jira
(v8.20.10#820010)