Re: Why Generics?
- From: "Chris Uppal" <chris.uppal@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 25 May 2005 09:52:41 +0100
Dale King wrote:
> [../] the new enumerations are (in my
> > understanding) just a little syntactic sugar provided by the javac
> > compiler. So clearly type safe enums were always possible.
>
> There is actually one part of enums that was not possible before and
> that was the ability to use them as cases in a switch statement.
It was always possible, the new enums don't generate code that couldn't be
expressed in "normal" Java. Supporting switch would require a fairly
unpleasant amount of wordy duplication, though. You'd have to have a public
static final int field corresponding the the 'ordinal' of each enum object,
which is obviously error prone unless the compiler does it for you.
OTOH, if you use your own implementation of the type-safe enum pattern, then
their object-nature is not hidden by the compiler and so you can use
polymorphism to avoid having to use switch statements in the first place.
-- chris
.
- Follow-Ups:
- Re: Why Generics?
- From: Chris Uppal
- Re: Why Generics?
- From: Phillip Lord
- Re: Why Generics?
- References:
- Why Generics?
- From: David Blickstein
- Re: Why Generics?
- From: Eric Sosman
- Re: Why Generics?
- From: Chris Uppal
- Re: Why Generics?
- From: Mike Schilling
- Re: Why Generics?
- From: Chris Uppal
- Re: Why Generics?
- From: David Blickstein
- Re: Why Generics?
- From: David Blickstein
- Re: Why Generics?
- From: Dale King
- Why Generics?
- Prev by Date: Re: fitting JTextArea to JFrame size
- Next by Date: Re: Will application J2ME MIDP 2.0 based of one device run another J2ME MIDP 2.0 device?
- Previous by thread: Re: Why Generics?
- Next by thread: Re: Why Generics?
- Index(es):
Relevant Pages
|