0

I was programming an enum to map possible MimeTypes of my application to file extensions. At some moment I forgot to delete the last , (comma) and to my surprise the code compiles fine:

package model;

public enum DocumentMimeType {
    PDF("pdf", "application/pdf"),
    DOC("doc", "application/msword"),
    RTF("rtf", "application/rtf"),
    XLS("xls", "application/vnd.ms-excel"),
    DOCX("docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"),
    XLSX("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
    GIF("gif", "image/gif"),
    JPG("jpg", "image/jpeg"),
    JPEG("jpeg", "image/jpeg"),
    BMP("bmp", "image/bmp"),
    PNG("png", "image/png"),;//-----> HERE the (,) BEFORE the (;)

    private final String extension;

    private final String mimeType;

    private DocumentMimeType(String extension, String mimeType) {
        this.extension = extension;
        this.mimeType = mimeType;

    }

    public String getExtension() {
        return this.extension;
    }

    public String getMimeType() {
        return this.mimeType;
    }
}

Out of curiosity I consulted the JLS - 8.9. Enum Types and again to my surprise this syntax is not permitted.

It is perhaps a bug then? it is intended? if so, why?

0 Answers0