groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexey Afanasiev (JIRA)" <>
Subject [jira] [Created] (GROOVY-8084) Captured types doesn't work in @CompileStatic
Date Wed, 08 Feb 2017 10:07:41 GMT
Alexey Afanasiev created GROOVY-8084:

             Summary: Captured types doesn't work in @CompileStatic
                 Key: GROOVY-8084
             Project: Groovy
          Issue Type: Bug
          Components: Static compilation, Static Type Checker
    Affects Versions: 2.4.8
            Reporter: Alexey Afanasiev

This code could be successfully compiled and executed. 
static def method(List<? extends Serializable> captured) {
    captured.add('some string')
    return captured

println method(new ArrayList<Integer>())

Looks like type check in groovy doesn't work with captured types. Is it a bug?

Is there any documentation about generics in groovy? 

Another kind of strange behaviour:
static def method() {
    List<Integer> list = new ArrayList<>()
    List<? extends Serializable> captured = list
    captured.add('some string') //Error:(7, 5) Groovyc: [Static type checking] - Cannot call
java.util.ArrayList <java.lang.Integer>#add(java.lang.Integer) with arguments [java.lang.String]
    return captured
Somehow type checking infered type of 'captured' variable to  java.util.ArrayList <java.lang.Integer>

This message was sent by Atlassian JIRA

View raw message