Java requires that the constants be defined first, prior to any fields or methods. Also, when there are fields and methods, the list of enum constants must end with a semicolon.
enum constants with compilation error:
public enum DayEnum {
String value;
/*Multiple markers at this line
- Syntax error on token "String", invalid Modifiers
- Syntax error on token ";", , expected*/
SUNDAY, MONDAY, TUESDAY, WEDNESDAY,THURSDAY, FRIDAY, SATURDAY;
}
enum constants as first statement without any compilation error:
public enum DayEnum {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY,THURSDAY, FRIDAY, SATURDAY;
String value;
}
No comments:
Post a Comment