Tan
Tan

Reputation: 1583

Eclipse doesn't complain about the syntax error

Please consider the following two scenarios where enumdeclaration has been used in the code. I am going through the code and clearly see that that there are syntax errors in the code and eclipse doesn't complain about it. I have mentioned in the code below where I suspect an error by the following line // A COMMA BEFORE SEMICOLON.

Please let me know if that is really an error or did I understood something wrong?

Scenario 1:

public enum SD implements MEEnum<SD> {

  ASCENDING("A", "Ascending", "ASC"),
  DESCENDING("D", "Descending", "DESC"), // A COMMA BEFORE SEMICOLON

  ;

  private final String code;
  private final String description;
  private final String command;

  private static final Map<String, SD> CODE_MAP =
    MEEnumUtil.buildCodeMap(SD.class);

  private SD(final String code, final String description, final String command) {
    this.code = code;
    this.description = description;
    this.command = command;
  }

  @JsonValue
  @Override
  public String getCode() {
    return code;
  }

  @Override
  public String getDescription() {
    return description;
  }

  @Override
  public SD toEnum(final String code) {
    return fromCode(code);
  }

  public String getCommand() {
    return command;
  }

  @JsonCreator
  public static SD fromCode(final String code) {
    return CODE_MAP.get(code);
  }

  public static SD fromCode(final char code) {
    return fromCode(String.valueOf(code));
  }

}

Scenario 2:

public enum FTSF implements MEEnum<FTSF>, SF {

  ID(DSF.ID.getCode(), "Transaction Id", DSF.ID.getColumnName()),
  CASH_AMOUNT("CashAmount", "Cash Amount", "cashAmount"),
  SECURITY_AMOUNT("SecurityAmount", "Security Amount", "securityAmount"),
  STATUS("Status", "Status", "status"),
  CREATED_TS(DSF.CREATED_TS.getCode(),
             DSF.CREATED_TS.getDescription(),
             DSF.CREATED_TS.getColumnName()),; // A COMMA BEFORE SEMICOLON

  private final String code;
  private final String description;
  private final String columnName;

  private static final Map<String, FTSF> CODE_MAP =
    MEEnumUtil.buildCodeMap(FTSF.class);

  private FTSF(final String code, final String description, final String columnName) {
    this.code = code;
    this.description = description;
    this.columnName = columnName;
  }

  @JsonValue
  @Override
  public String getCode() {
    return code;
  }

  @Override
  public String getDescription() {
    return description;
  }

  @Override
  public String getColumnName() {
    return columnName;
  }

  @Override
  public FTSF toEnum(final String code) {
    return fromCode(code);
  }

  @JsonCreator
  public static FTSF fromCode(final String code) {
    return CODE_MAP.get(code);
  }

}

Upvotes: 0

Views: 60

Answers (1)

Ted Hopp
Ted Hopp

Reputation: 234857

There's no syntax error here. The Java Language Specification clearly shows that a comma before the enum body declarations is allowed (but not required).

From Section 8.9.1:

EnumBody:
    { [EnumConstantList] [,] [EnumBodyDeclarations] }

...

and from Section 8.9.2:

EnumBodyDeclarations:
    ; {ClassBodyDeclaration}

Upvotes: 2

Related Questions