overide the equal, toString, hashcode methods in Enum

user12057507 :

I have one Enum like Below

public enum Game {
    CRICKET("cricket"),
    FOOTBALL("football"),
    VOLLEYBALL("volleyball")'

    private String val;

    private Game(String val) {
        this.val = val;
    }

    public String getValue() {
        return this.val;
    }
}

In here, Do I want to overide the equal(),hashCode(),toString() methods based on this What issues should be considered when overriding equals and hashCode in Java?

Andreas :

Question is meaningless, because you cannot override equal() and hashCode() of an enum.

That is because they are defined as final in the Enum class, which implicitly is the base class of all enum types.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=323536&siteId=1