search

Home  >  Q&A  >  body text

Java basic switch statement plus {} problem

Why do some books include double quotes here?
It can run with or without addition, is there any difference?

曾经蜡笔没有小新曾经蜡笔没有小新2768 days ago758

reply all(2)I'll reply

  • 怪我咯

    怪我咯2017-05-27 17:43:47

    Theoretically there is no difference, each case is an independent code block

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-27 17:43:47

    The statements in the case block are not actually the focus. As long as you reach this branch, you can just execute it. As for the problem of {} and double quotes you mentioned, adding {} means it is a block. Adding double quotes should be a string. , generally note that the case value of switch is generally of byte, char, short, int or enum type. The String type is supported after JDK1.7.

    reply
    0
  • Cancelreply