eclipse 为什么Eclipse要求在枚举中声明strictfp

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28306145/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 22:23:10  来源:igfitidea点击:

Why is Eclipse asking to declare strictfp inside enum

javaeclipseenumsstrictfp

提问by Anoop Dixith

I was trying out enum type in Java. When I write the below class,

我在 Java 中尝试 enum 类型。当我写下面的课时,

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 strictfpbut would it come here?

编译器说:Syntax error on token String, strictfp expected.
我知道是什么,strictfp但它会来这里吗?

回答by Firzen

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";
}

回答by rgettman

The enum constants must be first in the enum definition, above the privatevariable.

枚举常量必须首先出现在枚举定义中,在private变量之上。

Java requires that the constants be defined first, prior to any fields or methods.

Java 要求先定义常量,然后再定义任何字段或方法。

Try:

尝试:

public enum Day {
    MONDAY, TUESDAY, WEDNESDAY;
    private String mood;
    Day(String mood) {

    }
    Day() {

    }
  }