The following example shows how to implement custom constructor using enum.
All enum types implicitly implements java.io.Serializable and java.lang.Comparable.
Here we have defined an enum constructor which accepts direction and distance as constructor parameters.
Note that we have overridden toString method to provide our own custom message.
Enum provides the following APIs,
public static <E extends Enum<E>> E values();
- Returns all enum constants of this element type.
public final String name()
- Returns name of enum constant.
public final int ordinal()
- Returns position in its enum declaration starting with index ZERO.