1

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.

Bogdan T.
  • 668
  • 6
  • 13

1 Answers1

5

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()
Andy Turner
  • 137,514
  • 11
  • 162
  • 243