Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsfeed.utanet.at!newscore.univie.ac.at!aconews-feed.univie.ac.at!aconews.univie.ac.at!not-for-mail Newsgroups: comp.lang.java.programmer From: Andreas Leitgeb Subject: Re: looping through a list, starting at 1 References: <4e3745a2$0$305$14726298@news.sunsite.dk> <62239393-929c-4764-8c8e-9620a03a7b81@c29g2000yqd.googlegroups.com> <80346568-647c-4e27-8192-33e1765a09ce@glegroupsg2000goo.googlegroups.com> <4b71d212-c055-4af0-b9a9-13e3afbc5785@glegroupsg2000goo.googlegroups.com> <5b7d8805-7c33-4aa4-9b31-ae60c29a31f3@glegroupsg2000goo.googlegroups.com> Reply-To: avl@logic.at User-Agent: slrn/pre0.9.9-111 (Linux) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: Date: 12 Aug 2011 14:38:45 GMT Lines: 37 NNTP-Posting-Host: gamma.logic.tuwien.ac.at X-Trace: 1313159925 tunews.univie.ac.at 71616 128.130.175.3 X-Complaints-To: abuse@tuwien.ac.at Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7039 supercalifragilisticexpialadiamaticonormalizeringelimatisticantations wrote: > On 12/08/2011 4:32 AM, Andreas Leitgeb wrote: >> Lew wrote: >>> And my point was that there often is a way to put that >>> bifurcation into a compile-time structure rather than >>> run time. >> For classes I design myself: yes. It's called "virtual >> methods" and is a standard feature of Java ;-) >> That just isn't an option for foreign library classes >> if the "bifurcation" happens in my own code. >> I'm still eager to see an alternative to "instanceof" >> for the RandomAccess-case. > I wonder what the odds are of Java 8 adding a variant of switch/case > like this? > switch class (object) { > case java.util.RandomAccess: > // code goes here > break; > [...] If you ask for my opinion: zero. The particular usecase that RandomAccess is used for is in my humble opinion merely a syntactic trick almost same as defining a boolean getter in each relevant class that would merely return constantly true or constantly false depending on whether the implementing class has a certain property or not. This particular misuse makes it necessary to use instanceof just as the syntax for querying the property. Sweetening this particular misuse of interfaces with some additional syntactic sugar is so very the wrong way, that I really don't want say much more about it.