最近決定看看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在強大、變化、
所以當面試時被問到這些東西的時候別說的太絕對了。否則你會後悔的。