Why I cannot see the values
method when browsing the java.lang.Enum source code? I am using Intellij 2017.1.1 and JDK 1.8.0_131
Also, why is this method static
? I would have expected to be an instance method.
You can't see it because it is not defined on the Enum
class, but rather on specific subclasses of Enum
(i.e. your enum
's class).
This is because static methods are not polymorphic: a values
method on the subclass would not override the method in the superclass, but rather hide it.
You can get the enum constants for a class reflectively:
YourEnum.class.getEnumConstants()