Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!dedekind.zen.co.uk!zen.net.uk!hamilton.zen.co.uk!shaftesbury.zen.co.uk.POSTED!not-for-mail Date: Thu, 18 Aug 2011 10:47:21 +0100 From: RedGrittyBrick User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.20) Gecko/20110804 Thunderbird/3.1.12 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Using Enumerated Types as Array Indexes References: <4e4b0d81$0$314$14726298@news.sunsite.dk> <4e4b1fe4$0$314$14726298@news.sunsite.dk> <6d418cda-dab3-43df-a9ec-293b43f2bbd8@glegroupsg2000goo.googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Lines: 45 Message-ID: <4e4cdfab$0$2524$da0feed9@news.zen.co.uk> Organization: Zen Internet NNTP-Posting-Host: 754446f6.news.zen.co.uk X-Trace: DXC=3[G]ADLDiE<[BWGPC=LG0=nok4Z\WH8A8gPDHTT7?6Re`9dFnDUe7 X-Complaints-To: abuse@zen.co.uk Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7211 On 18/08/2011 10:29, Arved Sandstrom wrote: > On 11-08-17 11:17 AM, Lew wrote: >> Andreas Leitgeb wrote: >>> Arved Sandstrom wrote: >>>> Lew wrote: >>>>> JLS 10: [...] >>>>> IOW, you never index arrays with a byte, char or short. [...] >>>> I'm feeling slow this morning: how do we get problems with byte->int, >>>> short->int, or char->int again? >> >> One gets problems with byte->int and short->int with array indexes the way one gets into trouble with those widening conversions generally. The usual suspect is the lack of unsigned versions, so widening a (byte)0xA0, for example, would result in a negative index. >> >> One gets into trouble generally in programming when one thinks one thing is going on ("index takes a byte") whilst ignoring what's really going on (there's a widening conversion involved). You might get away with it most of the time, but occasionally such things trip you up. >> >> Why think about it imprecisely? Tell us the advantage of that, please. >> >>> array-indexing takes integers. That you can also throw byte/short/char >>> values at them without cast doesn't mean that arrays "take" those, but >>> only that such values get automatically converted to int before being >>> taken by the array for indexing. >>> >>> An example for something really "taking" byte-values: >>> foo(byte b) { ... } >> > I'll try my answer again, it seems not to have hit the airwaves. > > I don't see my imprecision: the JLS very clearly says that integral > widening primitive conversions result in *no* loss of information; this > is just common sense when you consider what's going on with char->int, > byte-int and short->int. > > I reiterate: the _JLS_ says that there is *no* loss of information. I > don't see why you believe the JLS is wrong. Exactly how are you getting > into trouble with integral widening primitive conversions? > > Furthermore, your assertion about indexing into an array with (byte)0x0A > (or any other legal byte value for that matter) is just plain incorrect, > and can be disproved in a minute or two. Indexing into any array with > (byte)0x0A returns the 11th element of a (sufficiently large) array. I think you misread Lew, he said (byte)0xA0 (not your 0x0A) doesn't get you the 161st element of a (sufficiently large) array. -- RGB