Enum.getConstants() Was: Automatic Resource Management, V.2

Rémi Forax forax at univ-mlv.fr
Mon Apr 20 11:33:40 PDT 2009

Stephen Colebourne a écrit :
> 2009/4/20 Joshua Bloch <jjb at google.com>:
>>> Why not return a List<Throwable> instead of an array (since
>>> Collections are generally nicer to use)?
>> I did think about this, but I opted to stick with the pattern in enum types'
>> values() method.  That decision was made for performance. Arguably the
>> performance issues are less important here, and the winds of change have
>> blown further away from arrays since then, so I'm definitely open to
>> switching this to a List if others think it's the right thing to do.
> Definitely List. Arrays should be considered a deprecated type in all
> JDK arrays at this point IMO. We need to move beyond thinking about
> raw performance as a reason.
> For example, I would have much preferred Enums to have had a Map of
> name to enum as a generated method. I currently have to have a code
> generator create this for every enum I write.
Hi Stephen,
Are you aware of Class.getEnumConstants() ?
I think that using this method you can write only one generic code for 
all enums.

Moreover, this map already exists in the class java.lang.Class, if you want
to expose it, you can vote for that RFE


More information about the coin-dev mailing list