Hi,
I was recently experimenting with @CompileStatic for performance improvements
and noticed that when using the short notation of putAt to assign a null value
I get the following error
[Static type checking] - Cannot call <T>
org.codehaus.groovy.runtime.DefaultGroovyMethods#putAt(java.util.List<T>, int,
T) with arguments [java.util.List<java.lang.String>, int, java.lang.Object]
Here is an example:
import groovy.transform.CompileStatic
import org.junit.jupiter.api.Test
@CompileStatic
class PutAtTest {
@Test
void testList() {
// These all work
def list = ['a', 'b', 'c']
list[0] = 'aa'
assert list[0] == 'aa'
list.set(2, null)
assert list[2] == null
list.putAt(0, null)
assert list[0] == null
// This Fails
list[1] = null
assert list[1] == null : "Short notation not working when assigning null"
}
@Test
void testMap() {
// These all work
def map = [a: 'foo', b: 'bar', c: 'baz']
map['a'] = 'aa'
assert map['a'] == 'aa'
map.put('c', null)
assert map['c'] == null
map.putAt('a', null)
assert map['a'] == null
// This Fails
map['b'] = null
assert map['b'] == null : "Short notation not working when assigning null"
}
}
Is this expected behavior or a bug? Does anyone know of workaround?
Regards,
Per