I have an Enum class in Airport.java
package test;
public enum Airport {
PHX,
LAX,
SFO,
NRT,
SIN;
Airport() {
}
}
and a Test class in Test.java
package test;
public class Test {
public static void main(String[] args) {
Airport a = Airport.PHX;
System.out.println(a);
System.out.println(String.valueOf(a));
System.out.println(a.name());
System.out.println(a.toString());
System.out.println(a.name() + '@' + Integer.toHexString(a.hashCode()));
}
}
The output for this is
PHX
PHX
PHX
PHX
PHX@15db9742
but shouldn't the output be
PHX
PHX
PHX
PHX@15db9742
PHX@15db9742
According the the Object API https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html the default Object.toString()
is getClass().getName() + '@' + Integer.toHexString(hashCode())