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
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: 14338
    
  22

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: an enum switch case label must be the unqualified name of an enumeration constant