Can the Java interview question switch be used for byte, long, and String?

1. Can switch work on byte, long, and String?

It can be used on byte, but not on long. The switch can be a string type, String (it can be used on String after jdk1.7).

2. Extended summary:

  • switch can act on: char, byte, short, int
  • Switch can act on: the packaging classes corresponding to char, byte, short, int
  • Switch cannot be used for: long, double, float, boolean, including their packaging classes

Guess you like

Origin blog.csdn.net/weixin_44296929/article/details/108318043