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


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

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 (4 earlier) <80346568-647c-4e27-8192-33e1765a09ce@glegroupsg2000goo.googlegroups.com> <slrnj45uke.6gl.avl@gamma.logic.tuwien.ac.at> <edffc0ad-6325-4622-93b4-abff84190e79@glegroupsg2000goo.googlegroups.com> <slrnj47vhe.6gl.avl@gamma.logic.tuwien.ac.at> <4b71d212-c055-4af0-b9a9-13e3afbc5785@glegroupsg2000goo.googlegroups.com>
Message-ID <slrnj486bs.6gl.avl@gamma.logic.tuwien.ac.at> (permalink)
Date 2011-08-11 18:03 +0000

Show all headers | View raw


Lew <lewbloch@gmail.com> 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 extends List,RandomAccess> T method(T raAcList) {
>>     // public static <T extends List> 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?

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