Re: limitations on using enum as generic parameter
On 02/11/2011 01:50 AM, Roedy Green wrote:
On Tue, 8 Feb 2011 09:50:32 -0800 (PST), "dalamb@cs.queensu.ca"
<david.alex.lamb@gmail.com> wrote, quoted or indirectly quoted someone
who said :
javac says "Cannot find symbol: method
values()". (the reference to Enum.valueof later also gets errors,
which is why I commented it out to simplify the test).
Even though enums are under the hood implemented as nested classes,
the Java language does think of enums as being classes or inheriting
from anything. You are trying to use them as if they were ordinary
classes.
To pull that off you would have to re-invent enums as ordinary
classes. To do that, have a look at the various enum decompilations I
have posted at http://mindprod.com/jgloss/enum.html
The 'enum' is a specialization of the "type-safe enumeration" with compiler
support. You can still implement type-safe enumerations by hand, just as
Joshua Bloch described in edition one of /Effective Java/, before Java 5.
People forget that enumerations are not limited to 'enum' exactly because
'enum' covers nearly all situations where you want a type-safe enumeration,
but in the end 'enum' is syntactic sugar for the latter. When 'enum' doesn't
do the job you roll your own, just like you use a spelled-out 'for' when a
for-each isn't enough.
--
Lew
Ceci n'est pas une fen??tre.
..___________.
|###] | [###|
|##/ | *\##|
|#/ * | \#|
|#----|----#|
|| | * ||
|o * | o|
|_____|_____|
|===========|