
|
If you were logged in you would be able to see more operations.
|
|
|
[-2, -6, 5].collect { if (it < 0) -it; else it }
returns "[null, null, null]," because the parser considers the last statement to be an "if" statement. Instead, we can propagate the optional return to the if and else clauses, so that the above will return [2, 6, 5].
James feels it should only be done for New Groovy.
|
|
Description
|
[-2, -6, 5].collect { if (it < 0) -it; else it }
returns "[null, null, null]," because the parser considers the last statement to be an "if" statement. Instead, we can propagate the optional return to the if and else clauses, so that the above will return [2, 6, 5].
James feels it should only be done for New Groovy. |
Show » |
|
Here is a workaround for jsr-01:
[-2, -6, 5].collect { if (it < 0) return -it; else return it }