• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

where does enum.values() come from?

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the Sun proficiency assessment for 310-055 there is a code sample thus:

enum Colors{RED,GREEN,BLUE,YELLOW};
public static void main(String[] args){
for(Colors c:Colors.values()){
if(c==Colors.GREEN)...

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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic