Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!69.16.185.11.MISMATCH!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: Using Enumerated Types as Array Indexes Date: Tue, 16 Aug 2011 20:45:00 -0700 (PDT) Organization: http://groups.google.com Lines: 21 Message-ID: <6d418cda-dab3-43df-a9ec-293b43f2bbd8@glegroupsg2000goo.googlegroups.com> References: <4e4b0d81$0$314$14726298@news.sunsite.dk> <4e4b1fe4$0$314$14726298@news.sunsite.dk> Reply-To: comp.lang.java.programmer@googlegroups.com NNTP-Posting-Host: 108.89.33.208 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1313552700 23681 127.0.0.1 (17 Aug 2011 03:45:00 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 17 Aug 2011 03:45:00 +0000 (UTC) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=108.89.33.208; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T User-Agent: G2/1.0 X-Google-Web-Client: true Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7153 On Tuesday, August 16, 2011 8:20:05 PM UTC-7, markspace wrote: > On 8/16/2011 6:56 PM, Arne Vajh=EF=BF=BDj wrote: > > byte/short/int/long integer types >=20 > OK, you mean for indexes? char works too, and long really doesn't -- it= =20 > has to be cast to an int. For longs, Java recognizes the loss of=20 > precision using long and requires that you acknowledge that the upper=20 > bits will simply be truncated. JLS 10: "The variables contained in an array have no names; instead they are refere= nced by array access expressions that use nonnegative integer index values.= " IOW, you never index arrays with a byte, char or short. If you try, you ge= t a widening conversion first, and if that results in a negative int value,= you got problems. --=20 Lew