Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #25760

Re: limitations on using enum as generic parameter

From Lew <noone@lewscanon.com>
Newsgroups comp.lang.java.programmer
Subject Re: limitations on using enum as generic parameter
Date 2011-02-11 07:40 -0500
Organization albasani.net
Message-ID <ij3amg$d74$1@news.albasani.net> (permalink)
References <76e9be77-f846-4559-82ec-1d774a8a6a0b@q36g2000yqn.googlegroups.com> <ftm9l65p83614vkg8cllgv0i9jjcmovgo6@4ax.com>

Show all headers | View raw


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|
|_____|_____|
|===========|

Back to comp.lang.java.programmer | Previous | Next | Find similar


Thread

Re: limitations on using enum as generic parameter Lew <noone@lewscanon.com> - 2011-02-11 07:40 -0500

csiph-web