I just noticed that Enum#toString
javadoc claims (my accent):
Returns the name of this enum constant contained in the declaration. This method can be overridden, although this is usually not or desirable . The type of enumeration should override this method when there is a more rigorous form of "programmer".
By default, toString()
and name()
return the same thing, so even once toString
been redefined, you can still access the enumeration name using the name()
method.
Does anyone know why overriding Enum#toString
undesirable?
EDIT: for reference, name()
javadoc (selection as in the original):
Returns the name of this enumeration constant, exactly as specified in the enumeration declaration. Most programmers should use the toString () method, preferring this, since the toString method can return a more convenient name . This method is primarily intended for use in specialized situations where the correctness depends on obtaining an exact name that will not differ from release to release.
source share