Am 27.09.2015 22:07, schrieb Edinson E. Padrón Urdaneta:
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... ?
Doesn't that produce a list with an int[] as single element? But yes,
this looks like a bug in static compilation. Unless, there is an
alternative asList method, which takes int[]... but I have not seenthat.
So this should not compile there. In normal Groovy this does not make
sense, from the API, but it is not really wrong.
bye blackdrag
--
Jochen "blackdrag" Theodorou
blog: http://blackdragsview.blogspot.com/