Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.3.3, 2.4.0-beta-1, 2.3.4, 2.3.5, 2.3.6
-
None
-
Windows 7 x64 SP1 on JVM 1.7.0_17
Description
When iterating over a List of Object[] in a .each closure and typing the parameter as Object[], the arguments in each iteration become an Object[] of Object[]. This does not happen if the parameter is def.
Object[] arr = new Object[1] arr[0] = 'test' List list = new ArrayList() list.add(arr) list.each { def obj -> assert obj[0] == 'test' } list.each { Object[] obj -> assert obj[0] == 'test' //fails. obj[0] is Object[]{'test'} instead of just 'test' }
This does not happen if the parameter is typed as String[]:
String[] arr = new String[1] arr[0] = 'test' List list = new ArrayList() list.add(arr) list.each { def obj -> assert obj[0] == 'test' } list.each { String[] obj -> assert obj[0] == 'test' // passes }
I have included a more thorough test case that demonstrates this behavior. Note that this may also apply to .collect or various other methods.
Attachments
Attachments
Issue Links
- relates to
-
GROOVY-7254 Problem With Null Parameter To Meta Method
- Closed