Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Eclipse asking to declare strictfp inside enum

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?

like image 337
Anoop Dixith Avatar asked Feb 03 '15 18:02

Anoop Dixith


3 Answers

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";
}
like image 192
Firzen Avatar answered Nov 02 '22 14:11

Firzen


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() {

    }
  }
like image 40
rgettman Avatar answered Nov 02 '22 12:11

rgettman


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;
 }
like image 26
Ritunjay kumar Avatar answered Nov 02 '22 13:11

Ritunjay kumar