Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: Using Enumerated Types as Array Indexes Date: Wed, 17 Aug 2011 16:04:09 +0200 Lines: 34 Message-ID: <9b2034Ff5mU1@mid.individual.net> References: <4e4b0d81$0$314$14726298@news.sunsite.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: individual.net 3+M2X9AcuF2ljwgSJ+wZcw3beDcwUS52nAsijWEEpTne+S5yQ= Cancel-Lock: sha1:bP3nyxQW26XvDa72cKASB9Ptm+k= User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7160 On 17.08.2011 14:29, David Lamb wrote: > On 16/08/2011 8:38 PM, Arne Vajh=F8j wrote: >> On 8/16/2011 10:53 AM, KevinSimonson wrote: >>> Java is a pretty handy language in its own right. But in Ada one >>> could define arrays to be indexed by enumerated types. Can Java do >>> that? If not, why not? >> >> Java is a simpler language than Ada. In Java array indexes are >> int and you have byte/short/int/long types and that is it. > > Sure -- but if Enums had been in the language from the beginning, then > it might have occurred to people that array indexes could be "any type > with a method 'int ordinal()'" (with the appropriate caveat about being= > in range 0..length-1) Or we had an interface Countable { int ordinal(); } which Enum would=20 implement and which could be used for array indexing. Or... I don't=20 find it worthwhile to speculate about what could have happened if=20 something else happened. And please also notice that there is still EnumMap as Patricia pointed=20 out - type safe, efficient and all. Just because Ada does it this way=20 doesn't mean that it's the best way or that other languages must follow=20 suit. Kind regards robert --=20 remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/