aspose file tools*
The moose likes Beginning Java and the fly likes an enum switch case label must be the unqualified name of an enumeration constant Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "an enum switch case label must be the unqualified name of an enumeration constant" Watch "an enum switch case label must be the unqualified name of an enumeration constant" New topic
Author

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

Ronwaldo Cruz
Ranch Hand

Joined: Oct 17, 2006
Posts: 69
Hi,

I'm new to Java 5

Could somebody take a look at why there's a compiler error?

public class SLAComputer {

/** Creates a new instance of SLAComputer */
public SLAComputer() {
}

public static void main(String[] args) {

SLAComputer computer = new SLAComputer();

Ticket ticket = new Ticket(Ticket.Priority.ONE, new Date());

}

public Date computeSLA(Ticket ticket) {

Ticket.Priority priority = ticket.priority;
Date date = new Date();

switch(priority) {

case(Ticket.Priority.ONE): //do something with the date

}

return date;


}

}

class Ticket {

public enum Priority { ONE, TWO, THREE, FOUR }
public enum Day { BUSINESS, CALENDAR }

Priority priority;
Date loggedDAte;

Ticket(Priority priority, Date loggedDate) {

this.priority = priority;
this.loggedDAte = loggedDate;

}

}

The compiler says: "an enum switch case label must be the unqualified name of an enumeration constant"

Could somebody please help with this?

Thanks
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14269
    
  21

The error message means that you have to use this:

case ONE:

instead of "case(Ticket.Priority.ONE):".


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Ronwaldo Cruz
Ranch Hand

Joined: Oct 17, 2006
Posts: 69
Thanks. This helps
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: an enum switch case label must be the unqualified name of an enumeration constant