Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #7022

Re: looping through a list, starting at 1

Newsgroups comp.lang.java.programmer
From Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at>
Subject Re: looping through a list, starting at 1
References (6 earlier) <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> <ad5e70fc-8d7b-47a7-83ff-50ec72b71faa@glegroupsg2000goo.googlegroups.com>
Message-ID <slrnj4805r.6gl.avl@gamma.logic.tuwien.ac.at> (permalink)
Date 2011-08-11 16:18 +0000

Show all headers | View raw


Lew <lewbloch@gmail.com> wrote:
> 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.

Fair enough. If I was to write code that was supposed to work for both
types (with or without a particular marker interface), then in the part
for "no marker" (as statically determined) I'd better still add a runtime-
check for it. In theory, theory and practise are the same, in practise 
they aren't. :-)

>> 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.

I wonder, if that is done in practise. E.g.: do you happen to know code
in the Java Standard Library or other renowned project that does this kind
of static check for a marker-interface?

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

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