Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes SCJP 5: Q on enums Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "SCJP 5: Q on enums" Watch "SCJP 5: Q on enums" New topic
Author

SCJP 5: Q on enums

Henry Zheng
Ranch Hand

Joined: Jan 24, 2004
Posts: 60
Hi all,

I have some questions regarding to enums, please shed some light

1) In the API document, the java.lang.Enum was declared as Class Enum<E extends Enum<E>>, but isn't it a recursive declaration? what does it mean then? "The type parameter should be a type extends Enum<E> in which E is itself?" -- just too complicated for me.

2) Where is the static values() method declared? I didn't find it in the Enum class, however.

Thanks

(SCJP 5 prefix added to topic title)
[ January 12, 2005: Message edited by: Barry Gaunt ]

Henry Zheng<br /> <br />I went numb when I learned to see.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

Enums have 2 implictly defined methods

public static E[] values();

public static E valueOf(String name);


Groovy
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
On the topic of enums, I noticed that Enum.valueOf is documented to throw NullPointerException if enumType is null, however, an IllegalArgumentException is thrown, at least by the Sun 1.5.0 VM on win32.

I'd bother raising a bug, or checking if it already exists, if it wasn't such a mission to use the bug parade.


Tony Morris
Java Q&A (FAQ, Trivia)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: SCJP 5: Q on enums
 
Similar Threads
Extending a enum with enum's type
Getting a random element from an Enum
Cannot understand enum class syntax
Iterating through unknown enum type variable
enum in Tiger