Nov 1, 2018

How to fix Java: an enum switch case label must be the unqualified name of an enumeration constant

Java enum in switch case Example

private enum SortType {
        Count, Date;
    }

    private SortType currentSortType;

    public void onSort(SortEvent event) {

        switch (SortType.valueOf(event.getSortColumn().getHeaderText())) {
            case Count:
                //do sth
                currentSortType = SortType.Count;
                break;
            case Date:
                //do sth
                currentSortType = SortType.Date;
                break;
        }
    }

In the case statement, use for example: Count, not SortType.Count