Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #7020
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!news2.arglkargh.de!easy.in-chemnitz.de!feeder.news-service.com!feeder3.cambriumusenet.nl!feed.tweaknews.nl!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
|---|---|
| From | Lew <lewbloch@gmail.com> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: looping through a list, starting at 1 |
| Date | Thu, 11 Aug 2011 07:14:09 -0700 (PDT) |
| Organization | http://groups.google.com |
| Lines | 43 |
| Message-ID | <ad5e70fc-8d7b-47a7-83ff-50ec72b71faa@glegroupsg2000goo.googlegroups.com> (permalink) |
| References | <list-20110802003845@ram.dialup.fu-berlin.de> <4e3745a2$0$305$14726298@news.sunsite.dk> <62239393-929c-4764-8c8e-9620a03a7b81@c29g2000yqd.googlegroups.com> <j19jcs$fad$1@Gaia.teknon.de> <80346568-647c-4e27-8192-33e1765a09ce@glegroupsg2000goo.googlegroups.com> <slrnj45uke.6gl.avl@gamma.logic.tuwien.ac.at> <DlD0q.35597$g12.31437@newsfe20.iad> <slrnj462qe.6gl.avl@gamma.logic.tuwien.ac.at> <fNN0q.575745$SG4.165292@newsfe03.iad> <slrnj47fmu.6gl.avl@gamma.logic.tuwien.ac.at> |
| 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 1313072135 29786 127.0.0.1 (11 Aug 2011 14:15:35 GMT) |
| X-Complaints-To | groups-abuse@google.com |
| NNTP-Posting-Date | Thu, 11 Aug 2011 14:15:35 +0000 (UTC) |
| Cc | avl@logic.at |
| In-Reply-To | <slrnj47fmu.6gl.avl@gamma.logic.tuwien.ac.at> |
| 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:7020 |
Show key headers only | View raw
On Thursday, August 11, 2011 4:37:02 AM UTC-7, Andreas Leitgeb wrote: > Arved Sandstrom <asandstr...@eastlink.ca> wrote: > > On 11-08-10 07:50 PM, Andreas Leitgeb wrote: > >> How would I write a method (overload) that would only take an > >> object if it is both List and RandomAccess? (Afaik: no way, but > >> I might perhaps miss something.) > > Pretty much in the standard way, which would take advantage of the > > marker interface in a way suggested by Bloch: you create an interface > > that extends List and RandomAccess, and concrete classes implement that. > > That's just not applicable to the Collections framework as it is: > We've all been taught to use interface-names for the static type > of variables to hold whatever concrete implementation: > ArrayList l = new ArrayList(); // discouraged > List l = new ArrayList(); // encouraged No, that's not what we've been taught. We've been taught to use the type that most generally allows the compiler to enforce the specific contract we need. That does not always mean use the interface (not "names"), nor the most general interface. Sometimes you do want to peg a variable or return type to a specific implementation, or a specific interface, or an interface that mixes in two parent interfaces per Bloch. Don't make a religion of "use the (most general) interface" - the actual principle is "use the type that guarantees your contract". So 'RandomList extends List, RandomAccess' is perfectly acceptable. ... > That's of course just rambling. Marker-interfaces just aren't used that > way, but instead they are always checked at runtime. So, either Marker- Nope. Their value is when they're checked *at compile time*. It's the use at run time that is suspect. > interfaces (such as RandomAccess) are an anti-pattern themselves, or > that pattern is one declared exception to the "instanceof"-red flag. Marker interfaces are not an antipattern. Use of 'instanceof' is, often. Use marker interfaces for *compile time* safety. -- Lew
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
Re: looping through a list, starting at 1 Arne Vajhøj <arne@vajhoej.dk> - 2011-08-01 20:32 -0400
Re: looping through a list, starting at 1 Robert Klemme <shortcutter@googlemail.com> - 2011-08-02 02:42 -0700
Re: looping through a list, starting at 1 v_borchert@despammed.com (Volker Borchert) - 2011-08-02 19:32 +0000
Re: looping through a list, starting at 1 Lew <lewbloch@gmail.com> - 2011-08-10 09:00 -0700
Re: looping through a list, starting at 1 Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-10 21:39 +0000
Re: looping through a list, starting at 1 Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-08-10 19:10 -0300
Re: looping through a list, starting at 1 Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-10 22:50 +0000
Re: looping through a list, starting at 1 Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-08-11 07:02 -0300
Re: looping through a list, starting at 1 Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-11 11:37 +0000
Re: looping through a list, starting at 1 Lew <lewbloch@gmail.com> - 2011-08-11 07:14 -0700
Re: looping through a list, starting at 1 Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-11 16:18 +0000
Re: looping through a list, starting at 1 Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-08-11 17:39 -0300
Re: looping through a list, starting at 1 Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-12 08:09 +0000
Re: looping through a list, starting at 1 supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-08-11 09:52 -0400
Re: looping through a list, starting at 1 Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-08-11 17:26 -0300
Re: looping through a list, starting at 1 supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-08-11 20:11 -0400
Re: looping through a list, starting at 1 Lew <lewbloch@gmail.com> - 2011-08-10 20:31 -0700
Re: looping through a list, starting at 1 Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-11 16:07 +0000
Re: looping through a list, starting at 1 Lew <lewbloch@gmail.com> - 2011-08-11 09:20 -0700
Re: looping through a list, starting at 1 Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-11 18:03 +0000
Re: looping through a list, starting at 1 Lew <lewbloch@gmail.com> - 2011-08-11 12:55 -0700
Re: looping through a list, starting at 1 Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-12 08:32 +0000
Re: looping through a list, starting at 1 supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-08-12 09:09 -0400
Re: looping through a list, starting at 1 Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-12 14:38 +0000
Re: looping through a list, starting at 1 Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-08-12 14:51 +0000
csiph-web