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

Eric Milles commented on GROOVY-7147:
-------------------------------------

If "A" is replaced by "List" this works fine.  Otherwise I get an error that 
the type parameter cannot be supplied with type arguments.

> Generics problem with STC, cast to ArrayList works but cast to List doesn't
> ---------------------------------------------------------------------------
>
>                 Key: GROOVY-7147
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7147
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 2.4.0-beta-3
>         Environment: Groovy Version: 2.4.0-beta-3 JVM: 1.8.0_25 Vendor: 
> Oracle Corporation OS: Mac OS X
>            Reporter: UEHARA Junji
>            Priority: Major
>         Attachments: error5.groovy
>
>
> Following groovy code with @TypeChecked emits error at call to func3():
> {code}
> import groovy.transform.TypeChecked
> import java.util.function.*
> @TypeChecked
> static <A,T> void func2(A<Function<T,T>> func) {
> }
> @TypeChecked
> static <A,T> void func3(A<Function<T,T>> func, A<T> list) {
> }
> @TypeChecked
> def func(List<Integer> listParam) {
>     func2([{Integer f->f+1},  {Integer f->f+2}] as 
> List<Function<Integer,Integer>>)  // OK
>     
>     func3([{Integer f->f+1},  {Integer f->f+2}] as 
> List<Function<Integer,Integer>>, [1,2,3]) // [Static type checking] - Cannot 
> call <A,T> error5#func3(A, A) with arguments [java.util.List 
> <Function<Integer,Integer>>, java.util.List <java.lang.Integer>]
>     func3([{Integer f->f+1},  {Integer f->f+2}] as 
> ArrayList<Function<Integer,Integer>>, [1,2,3]) //OK
>     func3([{Integer f->f+1},  {Integer f->f+2}] as 
> List<Function<Integer,Integer>>, [1,2,3] as List<Integer>) // [Static type 
> checking] - Cannot call <A,T> error5#func3(A, A) with arguments 
> [java.util.List <Function<Integer,Integer>>, java.util.List <Integer>] 
>     func3([{Integer f->f+1},  {Integer f->f+2}] as 
> List<Function<Integer,Integer>>, listParam) // [Static type checking] - 
> Cannot call <A,T> error5#func3(A, A) with arguments [java.util.List 
> <Function<Integer,Integer>>, java.util.List <Integer>] 
> }
> func([1,2,3])
> {code}
> IMHO, 'List' type can be passed to generic function as well as 'ArrayList'.



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

Reply via email to