You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Mauro Molinari (Jira)" <ji...@apache.org> on 2019/09/02 12:15:00 UTC

[jira] [Commented] (GROOVY-9240) Better signature for ResourceGroovyMethods.traverse(File, Map, Closure) (and overloadings)

    [ https://issues.apache.org/jira/browse/GROOVY-9240?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16920820#comment-16920820 ] 

Mauro Molinari commented on GROOVY-9240:
----------------------------------------

This one gives the same error:

{code}
folder.traverse(type: FileType.FILES, nameFilter: ~/.../) { println it }
{code}
(I didn't know I can omit the {{[ ]}} parenthesis).

This one instead works:

{code}
folder.traverse([
  type: (Object) FileType.FILES,
  nameFilter: ~/.*\.(?i)pdf/
]) { println it }
{code}

My workaround is, however:

{code}
folder.traverse([
  type: (Object) FileType.FILES,
  nameFilter: ~/.*\.(?i)pdf/
] as Map<String, Object>) { println it }
{code}

> Better signature for ResourceGroovyMethods.traverse(File, Map<String, Object>, Closure) (and overloadings)
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-9240
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9240
>             Project: Groovy
>          Issue Type: Improvement
>          Components: groovy-jdk
>    Affects Versions: 2.5.8
>            Reporter: Mauro Molinari
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> When you try to perform the following invocation in a statically checked/compile Groovy class you'll get a compilation error:
> {code:groovy}
> myFolder.traverse([
> 			type: FileType.FILES,
> 			nameFilter: ~/.*\.(?i)pdf/
> 		]) { println it }
> {code}
> The error is: 
> {noformat}
> Groovy:[Static type checking] - Cannot call java.io.File#traverse(java.util.Map <java.lang.String, java.lang.Object>, groovy.lang.Closure) with arguments [java.util.LinkedHashMap <java.lang.String, java.io.Serializable>, groovy.lang.Closure] 
> {noformat}
> I think that more flexible and static type checker-friendly signatures for the {{traverse}} methods would be:
> {{ResourceGroovyMethods.traverse(File, Map<String, ?>, Closure)}}
> {{ResourceGroovyMethods.traverse(File, Map<String, ?>)}}



--
This message was sent by Atlassian Jira
(v8.3.2#803003)