This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes where does enum.values() come from? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "where does enum.values() come from?" Watch "where does enum.values() come from?" New topic

where does enum.values() come from?

Thomas Kennedy
Ranch Hand

Joined: Jan 20, 2008
Posts: 137
In the Sun proficiency assessment for 310-055 there is a code sample thus:

public static void main(String[] args){
for(Colors c:Colors.values()){

To my amazement, this compiles. So, OK, I gather enum is a concrete subclass of Enum. Right so far? And it adds the values() method? But where is this documented? I don't see it in the API anywhere.

Costs matter. Justice lies in processes not outcomes. Crime is caused by criminals.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

Hi Thomas,

Welcome to JavaRanch!

There are some things, like the "length" pseudo-instance-variable in arrays, or the "class" pseudo-static-variable, or the "this" member, or the "super()" method, that are more part of the language than part of the API, and this is one of them. The primary source for stuff like this is the Java Language Specification, browseable free online in HTML form. The third edition includes enums and other features introduced in Java 5.

Now, reading the JLS is not for everyone -- many people get this information "secondhand" through various Java language textbooks. But the JLS is the go-to book for deciding arguments and impressing your friends.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: where does enum.values() come from?
Similar Threads
Best way to compare string param to enum list to perform correct action
Getting a random element from an Enum
Question about constructing enums
Java colors