Eclipse 枚舉類報錯
阿新 • • 發佈:2017-10-16
枚舉類 error ict nbsp info pub imp syntax nta
當你寫一個枚舉類時,如果沒有在枚舉類的第一行寫有哪些枚舉值,那麽就會出現編譯報錯:Syntax error on token "String", strictfp expected
比如:
public enum Season2 implements TimeInfo {
private final String name; //此處會報錯:Syntax error on token "String", strictfp expected
private final String desc;
private Season2(String name, String desc) {
this.name = name;
this.desc = desc;
}
······
}
報錯的原因就是沒有在第一行寫明你有哪些枚舉值,修改如下:
public enum Season2 implements TimeInfo {
SPRING,SUMMER,FALL,WINTER; //列出你要定義的枚舉值,此時編譯通過
private final String name;
private final String desc;
private Season2(String name, String desc) {
this.name = name;
this.desc = desc;
}
······
}
Eclipse 枚舉類報錯