groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Edinson E. PadrĂ³n Urdaneta <edinson.padron.urdan...@gmail.com>
Subject Unexpected behavior with Arrays.asList and an array of primitives even under CompileStatic
Date Sun, 27 Sep 2015 20:07:05 GMT
The code:

1 @groovy.transform.CompileStatic
2 public class ToyingAround {
3     public static void main(String[] args) {
4         int[] myIntArray = [0, 1, 2, 3, 4];  // Change to braces for java
5         List<Integer> myIntegerList = Arrays.asList(myIntArray);
6
7         myIntArray[0] = 4;
8         myIntegerList.set(4, 0);
9
10        assert Arrays.toString(myIntArray) == "[4, 1, 2, 3, 4]";
11        assert myIntegerList.toString() == "[0, 1, 2, 3, 0]";
12        assert Arrays.toString(myIntArray) != myIntegerList.toString();
13    }
14}

As you can see, the CompileStatic transformation is not getting the error
in line 5. IntelliJ shows a warning and the Java compiler with the java
version of this code throws the following error:

Error:(5, 52) java: incompatible types: inference variable T has
incompatible bounds
    equality constraints: java.lang.Integer
    lower bounds: int[]

My question: is this the desire behavior? Is this an error that
CompileStatic is not catching by mistake? Or... ?

Thanks in advance and cheers.

Mime
View raw message