Re: Enum.valueOf(String)

2013-08-20 Thread Omair Majid
On 08/20/2013 04:09 PM, Eamonn McManus wrote: > It might occur to me to look at valueOf(Class, String) if I was > looking for a method to convert a string to an enum constant, but I > don't think it would occur to me to look there if I was looking for a > method to get all the values of an enum. I'

Re: Enum.valueOf(String)

2013-08-20 Thread Eamonn McManus
It might occur to me to look at valueOf(Class, String) if I was looking for a method to convert a string to an enum constant, but I don't think it would occur to me to look there if I was looking for a method to get all the values of an enum. I'm sure plenty of people end up using MyEnum.class.getE

Re: Enum.valueOf(String)

2013-08-20 Thread Jonathan Gibbons
Eamonn, See http://docs.oracle.com/javase/7/docs/api/java/lang/Enum.html#valueOf(java.lang.Class,%20java.lang.String) Note that for a particular enum type T, the implicitly declared public static T valueOf(String) method on that enum may be used instead of this method to map from a name to t

Re: Enum.valueOf(String)

2013-08-20 Thread Eamonn McManus
As I mentioned earlier in the thread, it's kind of user-hostile for the Enum javadoc to send the user to the JLS instead of just saying, even briefly, what the methods are. Even more so since it doesn't actually link to the relevant section of the JLS or in fact to the JLS at all. This is not a com

Re: Enum.valueOf(String)

2013-08-20 Thread Jonathan Gibbons
Well, I presume other learning materials for Java (tutorials, ... for dummies, etc) will explain the existence of these methods as part of the language feature that is "enum"s. Quite where the bytecodes for the methods comes from is implementation detail that should not need to be documented i

Re: Enum.valueOf(String)

2013-08-20 Thread Paul Benedict
So are you recommending not to alter the Javadoc of Enum to mention this fact? Going to the JLS is great for compiler developers, but it's not the first place for the end user. On Tue, Aug 20, 2013 at 8:48 AM, Jonathan Gibbons < jonathan.gibb...@oracle.com> wrote: > Paul, > > Enums are well cov

Re: Enum.valueOf(String)

2013-08-20 Thread Jonathan Gibbons
Paul, Enums are well covered in JLS 7, section 8.9. In particular, see 8.9.2, Enum Body Declarations, beginning at the line "In addition, if E is the name of an enum type, then that type has the following implicitly declared static methods:" -- Jon On 08/20/2013 06:27 AM, Paul Benedict wro

Re: Enum.valueOf(String)

2013-08-20 Thread Paul Benedict
Jon, it's not a problem with the method docs, per se. The issue is about how the generation isn't documented. My questioning started because I was using several enums without javadoc available, but I did have the source available, and couldn't figure out how the method came to be. Since I've asked,

Re: Enum.valueOf(String)

2013-08-19 Thread Jonathan Gibbons
I noticed this method is not listed in the Javadocs for 5/6/7/8 but it's part of every enum. Is this an oversight or is there a good reason why it's not documented? -- Cheers, Paul Paul, Can you give more details? On a s

Re: Enum.valueOf(String)

2013-08-19 Thread Paul Benedict
I have been working with classes that don't have javadoc attachments. The problem was I couldn't find the method in the source nor was the method part of the Enum class. So where did it materialize from? Now I know the answer: the compiler generates it. I really think this knowledge should be adde

Re: Enum.valueOf(String)

2013-08-19 Thread Alan Bateman
On 18/08/2013 05:07, Paul Benedict wrote: I think the generated method needs to be listed in the class javadoc at least. I presume it throws an exception too (like the other valueOf) if the String can't be resolved to a constant, but no user is going to discover this fact through the documentatio

Re: Enum.valueOf(String)

2013-08-17 Thread Paul Benedict
I think the generated method needs to be listed in the class javadoc at least. I presume it throws an exception too (like the other valueOf) if the String can't be resolved to a constant, but no user is going to discover this fact through the documentation. On Sat, Aug 17, 2013 at 12:32 AM, Nick

Re: Enum.valueOf(String)

2013-08-16 Thread Eamonn McManus
The valueOf method in Enum subclasses is static, so Enum itself can't usefully declare it. But the description of the Enum class could say in text what the generated methods are, rather than referring the reader to the JLS without even a link. If you forget what the methods are you can always look

Re: Enum.valueOf(String)

2013-08-16 Thread Nick Williams
Oh, yea. Duh. I completely forgot about it being static, which of course it would HAVE to be to be useful. Silly me. Maybe there's a new language feature in there somewhere. Abstract static methods? ;-) Still, yes. I would recommend that the JavaDoc for the Enum class list the signature and us

Re: Enum.valueOf(String)

2013-08-16 Thread Nick Williams
That method doesn't exist in the actual java.lang.Enum base class. It gets generated automatically when the enum is compiled and is part of the compiled enum class, not part of the Enum base class. With that said, I don't disagree that it could use some documentation. I've often wondered why ja

Enum.valueOf(String)

2013-08-16 Thread Paul Benedict
I noticed this method is not listed in the Javadocs for 5/6/7/8 but it's part of every enum. Is this an oversight or is there a good reason why it's not documented? -- Cheers, Paul