Community
Participate
Working Groups
The following small test program gives me unexpected results when compiling: package test import java.util.HashMap import java.util.Map import org.junit.Test import static org.junit.Assert.* class MapTest { @Test public def void testCreation() { val map = new HashMap<String,Long>() val one = "one" map.put(one, 1L) val esa = map.entrySet.toArray(<Map.Entry>newArrayOfSize(1)) assertNotNull("map.entrySet.toArray", esa) assertEquals("map.entrySet.toArray.length", 1, esa.length) // esa0 is an Object, but should be a Map.Entry! val esa0 = esa.get(0) assertNotNull("map.entrySet.toArray[0]", esa0) // assertEquals("map.entrySet.toArray[0].key", one, esa0.key) // assertEquals("map.entrySet.toArray[0].value", 1L, esa0.value) } } The problem is esa; is should be typed as a Map.Entry, but isn't. And because of that, the last two lines of the test method do not compile. The line "val esa0 = esa.get(0)" is compiled to: final Object esa0 = ((List<Map.Entry>)Conversions.doWrapArray(esa)).get(0); I am also surprised that <array>.get(x) *wraps the array in a List*. Until now, I was assuming get(int) and set(int) were simply mapped to array[int]; this could result in highly inefficient code...
It works when using <Map.Entry<?,?>>newArrayOfSize(1).
same with val Entry[] esa = #[null] val esa0 = esa.get(0) println(esa0)