An enum switch case label must be the unqualified name of an enumeration constant

Bug && fix

In switch casethe code block, I want to enummake a case distinction for the type of object. But an error is reported:
insert image description here
that is to say, casethe label behind needs to be changed, and it cannot be written like this ( enumeration type name. enumeration value ).
How to write it? Remove the enumeration type name. Just write the enumeration value .

insert image description here
Even if it is an enumeration class defined by yourself, the usage is the same.

Java switch official documentation

First of all, go to the official website document: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html
The following part of the document will be translated and analyzed.

  1. What are the variable types supported by the switch code block?
The switch Statement

A switch works with the byte, 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).

Basic type: byte short char int
String StringEnumeration type enum
Special type (a class that encapsulates the four supported basic types): Byte Short Character Integer.
That is to say, there are 4+2+4 or 10 types in total.

  1. The String type is supported from JDK 1.7 (switch code block).
Using Strings in switch Statements
In Java SE 7 and later, you can use a String object in the switch statement's expression. 

Guess you like

Origin blog.csdn.net/wuyujin1997/article/details/130911243