Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #7027
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: looping through a list, starting at 1 |
| Date | 2011-08-11 12:55 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <5b7d8805-7c33-4aa4-9b31-ae60c29a31f3@glegroupsg2000goo.googlegroups.com> (permalink) |
| References | (5 earlier) <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> <slrnj486bs.6gl.avl@gamma.logic.tuwien.ac.at> |
Andreas Leitgeb wrote:
> 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 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. :-(
Alas.
>> 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!
And my point was that there often is a way to put that bifurcation into a compile-time structure rather than run time. Doing 'instanceof' is a red flag that the type analysis is incomplete and there may be a compile-time way to do it instead.
>> 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".
The generic "you".
> 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?
Yes.
--
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