Where is the documentation for the values() method of Enum?
The method is implicitly defined (i.e. generated by the compiler).
From the JLS:
In addition, if
E
is the name of anenum
type, then that type has the following implicitly declaredstatic
methods:/** * Returns an array containing the constants of this enum * type, in the order they're declared. This method may be * used to iterate over the constants as follows: * * for(E c : E.values()) * System.out.println(c); * * @return an array containing the constants of this enum * type, in the order they're declared */ public static E[] values(); /** * Returns the enum constant of this type with the specified * name. * The string must match exactly an identifier used to declare * an enum constant in this type. (Extraneous whitespace * characters are not permitted.) * * @return the enum constant with the specified name * @throws IllegalArgumentException if this enum type has no * constant with the specified name */ public static E valueOf(String name);
You can't see this method in javadoc because it's added by the compiler.
Documented in three places :
- Enum Types, from The Java Tutorials
The compiler automatically adds some special methods when it creates an enum. For example, they have a static values method that returns an array containing all of the values of the enum in the order they are declared. This method is commonly used in combination with the for-each construct to iterate over the values of an enum type.
Enum.valueOf
class
(The special implicitvalues
method is mentioned in description ofvalueOf
method)
All the constants of an enum type can be obtained by calling the implicit public static T[] values() method of that type.
- Enum Types, Section 8.9, Java Language Specification
The values
function simply list all values of the enumeration.