开发者

Less than in Groovy case/switch statement

开发者 https://www.devze.com 2022-12-29 09:13 出处:网络
I have the following switch statement switch (points) { case 0: name = \"new\"; break; case 1..14: badgeName = \"bronze-coin\"; break;

I have the following switch statement

    switch (points) {
       case 0: name = "new"; break;
       case 1..14: badgeName = "bronze-coin"; break;
       case 15..29: badgeName = "silver-coin"; 开发者_运维知识库break;
       default: badgeName = "ruby";
    }

I'd like the first case (case 0) to include points less than or equal to 0. How can I do this in Groovy?


switch(points)
{
    case Integer.MIN_VALUE..0: badgeName = "new"; break;
    case 1..14: badgeName = "bronze-coin"; break;
    case 15..29: badgeName = "silver-coin"; break;
    default: badgeName = "ruby";
}


case { it instanceof Integer && it < 0 }:
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号