Groovy 2.1.0 weird behaviour of switch-case-break statement with @CompileStatic -
i'm novice groovy programmer, , faced weird behaviour of switch-case-break statement static compilation (@compilestatic
annotation). seems break
s ignored. bug or i've missed while reading documentation.
environment:
- groovy sdk 2.1.0 - oracle jdk build 1.7.0_13-b20 on mac os x lion 10.7.5
test case:
import groovy.transform.compilestatic @compilestatic class test { def test() { ['a', 'b', 'c'].each { string val -> switch (val) { case 'a' : println("${val} casea") break case 'b' : println("${val} caseb") break default : println("${val} default") } } } } (new test()).test()
output:
a casea caseb default b caseb b default c default
second test: comment @compilestatic
and everithing works fine:
a casea b caseb c default
this seems bug in groovy 2.1.0 (thanks posting jira, looks fixed in groovy 2.1.1)
as workaround until released, can utilize labeled blocks case statements break
switch (val) { case 'a' : a:{ println("${val} casea") break } case 'b' : b:{ println("${val} caseb") break } default : println("${val} default") }
groovy switch-statement compile-static
No comments:
Post a Comment