You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@groovy.apache.org by Nathan Harvey <na...@gmail.com> on 2017/12/07 19:08:12 UTC

Functional interfaces and CompileStatic

Static compilation fails to recognize type parameters when functional
interfaces are used and a variable name is specified without a type. For
example:



Compiling this reports the error: [Static type checking] - Cannot find
matching method java.lang.Object#toUpperCase(). Please check if the declared
type is right and if the method exists.

The same error does not occur when using a Closure annotated with
@ClosureParams.



--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html

Re: Functional interfaces and CompileStatic

Posted by "Daniel.Sun" <su...@apache.org>.
Good job!



--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html

Re: Functional interfaces and CompileStatic

Posted by Paul King <pa...@asert.com.au>.
Nice! I'll check it tomorrow! :-)

On Mon, Dec 11, 2017 at 11:10 PM, Алексей Афанасьев <me...@gmail.com>
wrote:

> I've submitted pull request for this issue https://github.com/
> apache/groovy/pull/643 . There are at least two issues reported about
> this problem https://issues.apache.org/jira/browse/GROOVY-7061, h
> ttps://issues.apache.org/jira/projects/GROOVY/issues/GROOVY-8241.
>
> 2017-12-08 10:55 GMT+03:00 Konstantin Boudnik <co...@apache.org>:
>
>> Yup,
>>
>> Apache mailing lists do not accept attachments.
>> --
>>   With regards,
>> Konstantin (Cos) Boudnik
>> 2CAC 8312 4870 D885 8616  6115 220F 6980 1F27 E622
>>
>> Disclaimer: Opinions expressed in this email are those of the author,
>> and do not necessarily represent the views of any company the author
>> might be affiliated with at the moment of writing.
>>
>>
>> On Thu, Dec 7, 2017 at 10:39 PM, Nathan Harvey <na...@gmail.com>
>> wrote:
>> > Apologies, the mailing list removed my code (forum, anyone?). Here it
>> is:
>> >
>> > @CompileStatic
>> > class SampleClass {
>> >         public void sample(Consumer<String> consumer) {}
>> >         public static void main(String[] args) {
>> >                 new SampleClass().sample({ String str ->
>> str.toUpperCase() }) // passes
>> >                 new SampleClass().sample({ it.toUpperCase() }) // passes
>> >                 new SampleClass().sample({ str -> it.toUpperCase() })
>> // fails
>> >         }
>> > }
>> >
>> >
>> >
>> > --
>> > Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
>>
>
>

Re: Functional interfaces and CompileStatic

Posted by Алексей Афанасьев <me...@gmail.com>.
I've submitted pull request for this issue
https://github.com/apache/groovy/pull/643 . There are at least two issues
reported about this problem
https://issues.apache.org/jira/browse/GROOVY-7061,
https://issues.apache.org/jira/projects/GROOVY/issues/GROOVY-8241.

2017-12-08 10:55 GMT+03:00 Konstantin Boudnik <co...@apache.org>:

> Yup,
>
> Apache mailing lists do not accept attachments.
> --
>   With regards,
> Konstantin (Cos) Boudnik
> 2CAC 8312 4870 D885 8616  6115 220F 6980 1F27 E622
>
> Disclaimer: Opinions expressed in this email are those of the author,
> and do not necessarily represent the views of any company the author
> might be affiliated with at the moment of writing.
>
>
> On Thu, Dec 7, 2017 at 10:39 PM, Nathan Harvey <na...@gmail.com>
> wrote:
> > Apologies, the mailing list removed my code (forum, anyone?). Here it is:
> >
> > @CompileStatic
> > class SampleClass {
> >         public void sample(Consumer<String> consumer) {}
> >         public static void main(String[] args) {
> >                 new SampleClass().sample({ String str ->
> str.toUpperCase() }) // passes
> >                 new SampleClass().sample({ it.toUpperCase() }) // passes
> >                 new SampleClass().sample({ str -> it.toUpperCase() }) //
> fails
> >         }
> > }
> >
> >
> >
> > --
> > Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
>

Re: Functional interfaces and CompileStatic

Posted by Konstantin Boudnik <co...@apache.org>.
Yup,

Apache mailing lists do not accept attachments.
--
  With regards,
Konstantin (Cos) Boudnik
2CAC 8312 4870 D885 8616  6115 220F 6980 1F27 E622

Disclaimer: Opinions expressed in this email are those of the author,
and do not necessarily represent the views of any company the author
might be affiliated with at the moment of writing.


On Thu, Dec 7, 2017 at 10:39 PM, Nathan Harvey <na...@gmail.com> wrote:
> Apologies, the mailing list removed my code (forum, anyone?). Here it is:
>
> @CompileStatic
> class SampleClass {
>         public void sample(Consumer<String> consumer) {}
>         public static void main(String[] args) {
>                 new SampleClass().sample({ String str -> str.toUpperCase() }) // passes
>                 new SampleClass().sample({ it.toUpperCase() }) // passes
>                 new SampleClass().sample({ str -> it.toUpperCase() }) // fails
>         }
> }
>
>
>
> --
> Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html

Re: Functional interfaces and CompileStatic

Posted by Nathan Harvey <na...@gmail.com>.
Hi Paul, I didn't see one on JIRA. I looked for one with the "static
compilation" component. If you can't find it either, I'll go ahead and
create one.



--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html

Re: Functional interfaces and CompileStatic

Posted by Paul King <pa...@asert.com.au>.
I believe this is a known bug/limitation with an existing Jira.

On Fri, Dec 8, 2017 at 5:39 AM, Nathan Harvey <na...@gmail.com>
wrote:

> Apologies, the mailing list removed my code (forum, anyone?). Here it is:
>
> @CompileStatic
> class SampleClass {
>         public void sample(Consumer<String> consumer) {}
>         public static void main(String[] args) {
>                 new SampleClass().sample({ String str -> str.toUpperCase()
> }) // passes
>                 new SampleClass().sample({ it.toUpperCase() }) // passes
>                 new SampleClass().sample({ str -> it.toUpperCase() }) //
> fails
>         }
> }
>
>
>
> --
> Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
>

Re: Functional interfaces and CompileStatic

Posted by Nathan Harvey <na...@gmail.com>.
Apologies, the mailing list removed my code (forum, anyone?). Here it is:

@CompileStatic
class SampleClass {
	public void sample(Consumer<String> consumer) {}
	public static void main(String[] args) {
		new SampleClass().sample({ String str -> str.toUpperCase() }) // passes
		new SampleClass().sample({ it.toUpperCase() }) // passes
		new SampleClass().sample({ str -> it.toUpperCase() }) // fails
	}
}



--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html