Why can't I use switch statement on a String?

前端 未结 16 2050
面向向阳花
面向向阳花 2020-11-21 07:57

Is this functionality going to be put into a later Java version?

Can someone explain why I can\'t do this, as in, the technical way Java\'s switch state

16条回答
  •  梦如初夏
    2020-11-21 08:11

    It's a breeze in Groovy; I embed the groovy jar and create a groovy utility class to do all these things and more which I find exasperating to do in Java (since I am stuck using Java 6 in the enterprise.)

    it.'p'.each{
    switch (it.@name.text()){
       case "choclate":
         myholder.myval=(it.text());
         break;
         }}...
    

提交回复
热议问题