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> 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: 11 Aug 2011 18:03:40 GMT Lines: 51 NNTP-Posting-Host: gamma.logic.tuwien.ac.at X-Trace: 1313085820 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:7024 Lew wrote: > Andreas Leitgeb wrote: >> Lew wrote: >>> Andreas Leitgeb wrote: >>>> Lew wrote: >>>>> Volker Borchert wrote: >>>>>> if (l instanceof RandomAccess) { >>>>> Tests on type like this are an antipattern. >>>> Are marker-interfaces (which RandomAccess is, iirc) already an >>>> antipattern, or is there a different way to check for them, [...] >>> With generics you can use type intersections so that something has to be >>> both 'List' and 'RandomAccess' (again, say) even to reach the call or the >>> class or whatever. >> Interesting stuff! (but still falls a bit short): >> public static T method(T raAcList) { >> // public static T method(T anyList) { > You cannot have two erasure-equivalent methods in the same class, ... It isn't obvious to me, how these really *need* to be erasure-equivalent. I mean, obviously they are, but that's just a fact of Java as it is, not a principial necessity. If Java had a consistent model of intersection types even outside of generics, like "List & RandomAccess raList = new ArrayList();", then the erased type of first method()'s "T" would be just that intersection type, and the methods would be obviously erasure- *un*equivalent. No need to tell me it ain't so. I know. :-( > The generics trick is suitable when you want to insist > that the argument be of the particular type, not when > you want to bifurcate as you indicated. But bifurcation was the context of this discussion about "instanceof"-red flags! > It seems as though perhaps you are in a situation where you > want to fork on the type at run-time, ... Well, not me. See Volker's posting up-thread for the context in which he suggested use of "instanceof". Forking on "implementing or not implementing a particular marker-interface" is an entirely different situation from asserting a particular interface/type. I'm all with you that the latter be done at compile-time whenever even remotely possible. Now, would you call "instanceof" in the specific context of bifurcation (with none of the branches just barfing) still a red flag?