You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Peter Ledbrook (JIRA)" <ji...@apache.org> on 2016/02/03 11:37:39 UTC
[jira] [Commented] (GROOVY-7061) Type inference not working for
Collections.sort()
[ https://issues.apache.org/jira/browse/GROOVY-7061?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15130209#comment-15130209 ]
Peter Ledbrook commented on GROOVY-7061:
----------------------------------------
Something else a group of us discovered is that if you replace
{code}
filter { s -> s.length() < 10 }
{code}
with
{code}
filter { it.length() < 10 }
{code}
then the compile-time type checker is happy. So the problem only seems to occur with explicitly declared, untyped closure arguments.
> Type inference not working for Collections.sort()
> -------------------------------------------------
>
> Key: GROOVY-7061
> URL: https://issues.apache.org/jira/browse/GROOVY-7061
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Affects Versions: 2.3.6, 2.4.5
> Reporter: Peter Ledbrook
>
> In this example:
> {code}
> import groovy.transform.TypeChecked
> doIt()
> @TypeChecked
> void doIt() {
> List<Integer> nums = [1, 2, 3, -2, -5, 6]
> // nums.sort { a, b -> a.abs() <=> b.abs() }
> Collections.sort(nums, { a, b -> a.abs() <=> b.abs() })
> }
> {code}
> the type checking fails on the closure arguments (no method {{abs()}} on type {{Object}}). Interestingly, it works fine for the line that's commented out.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)