当你写一个枚举类时,如果没有在枚举类的第一行写有哪些枚举值,那么就会出现编译报错: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;
    }

  ······

}

相关文章:

  • 2021-09-24
  • 2021-09-24
  • 2018-06-06
  • 2019-09-15
  • 2021-07-18
  • 2021-12-16
  • 2021-08-23
  • 2020-04-30
猜你喜欢
  • 2020-05-02
  • 2022-01-06
  • 2021-05-17
  • 2021-09-24
  • 2021-09-24
  • 2021-11-03
  • 2021-12-06
相关资源
相似解决方案