From: Marc van Dongen on
Howsagoin,


I know what the class method values( ) of enum classes is for, but
don't seem to
be able to find the API in the API documentation on
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Enum.html,

I'd appreciate it if somebody could let me know where to find it.

Thanks in advance for your help.

Regards,


Marc van Dongen
From: Peter Duniho on
Marc van Dongen wrote:
> Howsagoin,
>
>
> I know what the class method values( ) of enum classes is for, but
> don't seem to
> be able to find the API in the API documentation on
> http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Enum.html,
>
> I'd appreciate it if somebody could let me know where to find it.

You should be looking in the latest version documentation (i.e. Java 6:
http://java.sun.com/javase/6/docs/api/java/lang/Enum.html).

But, that particular method is, as I understand it, automatically
generated by the compiler. It won't show up in the API documentation,
as it's not actually part of the java.lang.Enum type itself, but rather
something that shows up in each actual declared enum automatically.

You can probably find details in the Java specification.

Pete
From: Patricia Shanahan on
Peter Duniho wrote:
> Marc van Dongen wrote:
>> Howsagoin,
>>
>>
>> I know what the class method values( ) of enum classes is for, but
>> don't seem to
>> be able to find the API in the API documentation on
>> http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Enum.html,
>>
>> I'd appreciate it if somebody could let me know where to find it.
>
> You should be looking in the latest version documentation (i.e. Java 6:
> http://java.sun.com/javase/6/docs/api/java/lang/Enum.html).
>
> But, that particular method is, as I understand it, automatically
> generated by the compiler. It won't show up in the API documentation,
> as it's not actually part of the java.lang.Enum type itself, but rather
> something that shows up in each actual declared enum automatically.
>
> You can probably find details in the Java specification.

Specifically, see
http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.9

Patricia
From: markspace on
Peter Duniho wrote:

> You can probably find details in the Java specification.


Yup, you can find it in section 8.9 of the JLS:

<http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.9>

"In addition, if E is the name of an enum type, then that type has the
following implicitly declared static 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);

"

In my opinion, the Java doc is defective for not mentioning these
methods. It should copy-and-paste the above section into the Java doc
for the Enum class, so that the information is ready-to-hand for anyone
looking at the Enum methods.
From: Peter Duniho on
markspace wrote:
> [...]
> In my opinion, the Java doc is defective for not mentioning these
> methods. It should copy-and-paste the above section into the Java doc
> for the Enum class, so that the information is ready-to-hand for anyone
> looking at the Enum methods.

I agree, sort of.

I understand the reasoning behind not including those methods in the
class documentation proper. They _aren't_ part of the java.lang.Enum
type, and it would be inconsistent for the docs to pretend that they are.

However, the remarks section for the java.lang.Enum type itself is
incredibly sparse, providing no guidance whatsoever on the proper usage,
common patterns, etc. of enums. It should provide those details, and in
those details, it would specifically mention the values() and valueOf()
method that are generated by the compiler in concrete enum types.

I don't think that the methods should in fact appear in the list of
methods for the java.lang.Enum class, but yes�definitely, the
documentation should discuss them _somewhere_.

Pete