1 Reply Latest reply: May 20, 2012 12:21 PM by jschellSomeoneStoleMyAlias RSS

    JDK1_7 Switch

    937915
      In reference to the new feature of switch taking Case value as String.

      1) Does it make direct jumps like in the case of int?
      2) Which one is faster the int or the string? I feel it could be same if it directly jumps.
      3) Are these String kept into the "String Pool" or kind of place. In other words how much it impact on memory?
        • 1. Re: JDK1_7 Switch
          jschellSomeoneStoleMyAlias
          sinhasaurabhy2k wrote:
          In reference to the new feature of switch taking Case value as String.

          1) Does it make direct jumps like in the case of int?
          Not exactly sure what you mean - a jump is a jump.
          However since the bytes codes have not change there is no string table byte code (so ie no 'lookupswitch'), which probably means the most likely implementation is just a sequence of ifs.
          2) Which one is faster the int or the string? I feel it could be same if it directly jumps.
          Hardly since the string comparison takes longer.
          3) Are these String kept into the "String Pool" or kind of place.
          Literals are always in the pool.
          In other words how much it impact on memory?
          If you have enough switch statements with strings versus object creation that you can even measure the usage I would suspect that your design is broken. Badly broken.