最近决定看看Java基础,又重新看了遍switch,记录下switch支持的类型:
A switch
works with thebyte
, short
, char
, and int
primitive data types.
It also works with enumerated types (discussed in Enum Types),
the String
class, and a few special classes that wrap certain primitive types: Character
, Byte
, Short
, and Integer
(discussed in Numbers and Strings).
Using Strings in switch Statements
In Java SE 7 and later, you can use a String
object in the switch
statement's expression
OK、看到上面对这句话就要注意了、不要过分的相信论坛太早的回复、
java在强大、变化、
所以当面试时被问到这些东西的时候别说的太绝对了。否则你会后悔的。