JDK 12 RFR of JDK-8173730: Stop including enhanced for-loop tip for enum values() method

Jonathan Gibbons jonathan.gibbons at oracle.com
Tue Sep 25 00:39:58 UTC 2018


Tagir,

The enum values are in an array, so you can use any of your favorite methods
for iterating over the contents of an array. You can still use an 
enhanced for loop,
if you so choose;  this edit is just about that hint being no longer 
necessary in the
generates documentation.

-- Jon

On 09/24/2018 05:06 PM, Tagir Valeev wrote:
> Hello!
>
> Sorry for stupid question, but what is modern alternative to iterate 
> over the enum values?
>
> With best regards,
> Tagir Valeev
>
> вт, 25 сент. 2018 г., 4:48 joe darcy <joe.darcy at oracle.com 
> <mailto:joe.darcy at oracle.com>>:
>
>     Hello,
>
>     Since enum types were added in JDK 5, which shipped GA in 2004, the
>     javadoc for the compiler-generated static values() method for
>     enums has
>     stated:
>
>     > Returns an array containing the constants of this enum type, in the
>     > order they are declared. This method may be used to iterate over
>     the
>     > constants as follows:
>     >
>     > for (RoundingMode c : RoundingMode.values())
>     >     System.out.println(c);
>
>     While the tip to use the enhanced for loop to iterate over the
>     constants
>     of the enum type may have been reasonable to include in 2004, IMO
>     it is
>     unnecessary and clutter in 2018. Therefore, please review the
>     changes for
>
>          JDK-8173730: Stop including enhanced for-loop tip for enum
>     values()
>     method
>     http://cr.openjdk.java.net/~darcy/8173730.0/
>     <http://cr.openjdk.java.net/%7Edarcy/8173730.0/>
>
>     to remove the generation of the for loop tip.
>
>     Patch below.
>
>     Docs builds complete successfully and elides the tip as expected.
>
>     Thanks,
>
>     -Joe
>
>     ---
>     old/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/doclets.properties
>
>     2018-09-24 14:31:57.943000000 -0700
>     +++
>     new/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/doclets.properties
>
>     2018-09-24 14:31:57.771000000 -0700
>     @@ -230,12 +230,7 @@
>       #Documentation for Enums
>       doclet.enum_values_doc.fullbody=\
>        Returns an array containing the constants of this enum type, in\n\
>     - the order they are declared. This method may be used to iterate\n\
>     - over the constants as follows:\n\
>     - <pre>\n\
>     - for ({0} c : {0}.values())\n\
>     -     System.out.println(c);\n\
>     - </pre>
>     + the order they are declared.
>
>       doclet.enum_values_doc.return=\
>       an array containing the constants of this enum type, in the
>     order they
>     are declared
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20180924/6269875d/attachment-0001.html>


More information about the compiler-dev mailing list