Friday, 15 August 2014

Java Enum values() method

I remember there being a values() method that provides all possible values of an Enumerated Type in Java. I checked the javadoc1 and couldn't find it...

But it exists.

Which is weird.

Luckily, someone else had the same problem and asked it in [2].

I was intriged so I looked up the Language Spec3. Yes, the method is available in each and every Enum class, but it is 'especially' inserted by the compiler and not inherited from the superclass4.

Luckily in the javadoc1, values() and valueOf(String) methods are both mentioned in the description of the valueOf(Class<T> , String) method (nowadays).


[1] Javadoc - Enum
[2] CodeRanch - Values method documented Enum
[3] Oracle - The Java Language Specification (Java 8)
[4] Oracle Java Tutorials - Enum Types

No comments:

Post a Comment