Re: values() of an Enumeration type that is a generic parameter?
- From: ylandrin@xxxxxxxxx
- Date: 23 May 2007 06:37:46 -0700
On May 13, 6:28 pm, Lew <l...@xxxxxxxxxxxxxxxxxxxx> wrote:
Lasse Reichstein Nielsen wrote:
Actually, the Class<T> object has the method "T[] getEnumConstants()"
that returns the values of an enum type (or null, if the Class is not
an enum), so reflection isn't needed anyway.
That /is/ reflection.
Hummmm... not exactly. getEnumConstants() is only available (i.e.
returns something other than null)
when the class *is* an Enum class. Not really the behavior you expect
from reflection, that should be
independant from hypotheses on the nature of the class, and report
type-checking failures through
a few, well-defined runtime exceptions.
In my opinion, this is rather a hack to implement inheritance-aware
static fields,
in the particular case of <E extends Enum<E>> E
valueOf(Class<E>,String). Look at the implementation of Enum-related
methods in Class... you could do the same thing with a static
Map<Class<? extends Enum>,Enum[]>,
that would let you implement <E extends Enum<E>> E[] values(Class<E>),
but with much less performance.
And what object is Class-common, but updated/able whith inheritance?
The Class object, of course!
--
YLS
.
- References:
- values() of an Enumeration type that is a generic parameter?
- From: Eric Smith
- Re: values() of an Enumeration type that is a generic parameter?
- From: Lasse Reichstein Nielsen
- Re: values() of an Enumeration type that is a generic parameter?
- From: Eric Smith
- Re: values() of an Enumeration type that is a generic parameter?
- From: Lasse Reichstein Nielsen
- Re: values() of an Enumeration type that is a generic parameter?
- From: Lew
- values() of an Enumeration type that is a generic parameter?
- Prev by Date: Acelet announces LimpidDebugger 2.0
- Next by Date: apache ant and subant
- Previous by thread: Re: values() of an Enumeration type that is a generic parameter?
- Next by thread: More enum confusion
- Index(es):
Relevant Pages
|