I was trying out enum type in Java. When I write the below class,
public class EnumExample {
public enum Day {
private String mood;
MONDAY, TUESDAY, WEDNESDAY;
Day(String mood) {
}
Day() {
}
}
}
Compiler says: Syntax error on token String, strictfp expected.
I do know what's strictfp
but would it come here?
You have maybe forgotten to add semicolon after last enum constant.
public enum Element {
FIRE,
WATER,
AIR,
EARTH, // <-- here is the problem
private String message = "Wake up, Neo";
}
The enum constants must be first in the enum definition, above the private
variable.
Java requires that the constants be defined first, prior to any fields or methods.
Try:
public enum Day {
MONDAY, TUESDAY, WEDNESDAY;
private String mood;
Day(String mood) {
}
Day() {
}
}
You can't define instance variable before enum elements/attributes.
public enum Day {
MONDAY("sad"), TUESDAY("good"), WEDNESDAY("fresh");
private String mood;
Day(String mood) {
this.mood = mood;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With