[jira] [Commented] (GROOVY-8285) Static compilation does not accept subclasses for generic arguments

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[jira] [Commented] (GROOVY-8285) Static compilation does not accept subclasses for generic arguments

JIRA jira@apache.org

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

Harsh Gupta commented on GROOVY-8285:
-------------------------------------

This used to compile on 2.3.10, which led me to think this will work on current version of groovy. I can see why this should not compile in java, so closing issue.

> Static compilation does not accept subclasses for generic arguments
> -------------------------------------------------------------------
>
>                 Key: GROOVY-8285
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8285
>             Project: Groovy
>          Issue Type: Bug
>         Environment: Groovy Version: 2.4.12 JVM: 1.8.0_121 Vendor: Oracle Corporation OS: Mac OS X
>            Reporter: Harsh Gupta
>            Priority: Critical
>
> This snippet does not compile.
> {code:Java}import groovy.transform.CompileStatic
> @CompileStatic
> class Scratch {
>     public static void main(String[] args) {
>         List<bar> listA
>         List<foo> listB = new ArrayList<>()
>         listB.add(new foo())
>         listA = listB
>     }
> }
> class bar {
>     public int blah() { return 12; }
> }
> class foo extends bar {
>     public int boo() { return 42; }
> }
> {code}
> Compilation errors:
> {quote}
> repro.groovy: 10: \[Static type checking\] - Incompatible generic argument types. Cannot assign java.util.ArrayList <foo> to: java.util.List <bar>
>  @ line 10, column 21.
>                listA = listB
> {quote}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)
Loading...