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


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

Re: Eclipse

From Andreas Leitgeb <avl@logic.at>
Newsgroups comp.lang.java.programmer
Subject Re: Eclipse
Date 2017-06-30 14:47 +0000
Organization A noiseless patient Spider
Message-ID <slrnolcpad.o2q.avl@logic.at> (permalink)
References <8b4bfc08-ccdb-40bf-a4f6-875d0cd9a058@googlegroups.com> <f4c93896-75b3-472d-9564-ee5f93839fcb@googlegroups.com> <5314f277-558b-43d1-8564-460ab8dab26a@googlegroups.com> <1b033cbe-4bc2-497f-9c93-e6e90b75f39b@googlegroups.com> <oj306u$gq0$1@dont-email.me>

Show all headers | View raw


It's a pity, that this imho-most-to-the-point post seems to have drowned
among all the others...  Main reason for my followup is really to give
it another chance to being seen, but I hope my answer isn't entirely
worthless beyond that goal.

Eric Sosman <esosman@comcast-dot-net.invalid> wrote:
>      To recapitulate:
>      - You have an ArrayList that is supposed to contain objects that
> implement MyCustomInterface.
>      - You have an object that is known to be a Component.
>      - There are lots and lots and lots of Component classes that do
> not implement MyCustomInterface.
>      - Therefore, it is at the very least "suspicious" that a list of
> MyCustomInterface instances is being examined for the presence of
> something that (for all Java knows) needn't implement MyCustomInterface.

>      It certainly doesn't strike me as an "error" to check for the
> presence of something that isn't there, or even of something that
> might turn out to be there under a different guise (a Component
> that does, in fact, implement MyCustomInterface).  Nonetheless, it
> does seem "suspicious,"

so far yes...

> just as it would be "suspicious" to look
> for a raw Component in a List<JButton>.

The case, where the reference type of the "needle" object is a
superclass or superinterface of the hay-type (of the haystack)
is a tad *less* suspicious, imho.

The case at hand, where these two types are just unrelated 
to Java's knowledge-at-the-point is somewhat suspicious. 

> Not as suspicious as looking
> for a JButton in a List<String>, but certainly odd.

This would indeed be a quite a tad *more* suspicious, namely in so
far as Java doesn't even let you explicitly directly *cast* JButton
to String.

>      - if (comp instanceof MyCustomInterface
>            && list.contains((MyCustomInterface) comp))

This is what I'd have suggested to Eric D., too.

I'd even see it as a serendipituous runtime benefit: no need
to even scan the list, if there's no chance of a hit in the first
place. That even counts for me as "algorithmic optimization" of
sort "don't do goofy things", rather than the usual "premature" one.

>      - @SuppressWarnings plus a lengthy comment

I think, I once saw it happen that a SuppressWarnings added for one 
Java compiler actually caused a warning about the "unnecessary"
suppresion by another Java compiler (iirc, it was netbeans versus
eclipse, but I only saw the eclipse side, and knew that someone
else was working on the project with netbeans, so it is possible that 
netbeans even showed the same warning) - I also don't remember the
annotation's argument (i.e. what warning even was to be suppressed)

Anyway, I'm reluctant about adding @SuppressWarnings for IDE-specific
warnings.

>      I would *not* recommend defeating the warning altogether

I usually do disable the IDE warnings about missing serialId fields,
but that's a different case. I agree, that the warning at hand is 
instead a generally useful one and rather not one to just disable
globally.

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


Thread

Eclipse Eric Douglas <e.d.programmer@gmail.com> - 2017-06-28 07:57 -0700
  Re: Eclipse Eric Douglas <e.d.programmer@gmail.com> - 2017-06-28 09:04 -0700
    Re: Eclipse Eric Douglas <e.d.programmer@gmail.com> - 2017-06-28 12:07 -0700
      Re: Eclipse Eric Douglas <e.d.programmer@gmail.com> - 2017-06-29 06:05 -0700
        Re: Eclipse Jerry Stuckle <jstucklex@attglobal.net> - 2017-06-29 09:32 -0400
          Re: Eclipse Eric Douglas <e.d.programmer@gmail.com> - 2017-06-29 06:42 -0700
        Re: Eclipse Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-06-29 09:47 -0400
          Re: Eclipse Andreas Leitgeb <avl@logic.at> - 2017-06-30 14:47 +0000
            Re: Eclipse Eric Douglas <e.d.programmer@gmail.com> - 2017-06-30 08:22 -0700
              Re: Eclipse Eric Douglas <e.d.programmer@gmail.com> - 2017-07-07 06:19 -0700
                Re: Eclipse Andreas Leitgeb <avl@logic.at> - 2017-07-13 09:29 +0000
        Re: Eclipse Martin Gregorie <martin@address-in-sig.invalid> - 2017-06-29 17:18 +0000
          Re: Eclipse Eric Douglas <e.d.programmer@gmail.com> - 2017-06-29 11:08 -0700
            Re: Eclipse Martin Gregorie <martin@address-in-sig.invalid> - 2017-06-29 18:58 +0000
              Re: Eclipse Eric Douglas <e.d.programmer@gmail.com> - 2017-06-29 12:55 -0700
                Re: Eclipse Martin Gregorie <martin@address-in-sig.invalid> - 2017-06-29 21:31 +0000
                Re: Eclipse Eric Douglas <e.d.programmer@gmail.com> - 2017-06-30 04:55 -0700
                Re: Eclipse Martin Gregorie <martin@address-in-sig.invalid> - 2017-06-30 13:02 +0000
              Re: Eclipse Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-06-29 16:34 -0400
                Re: Eclipse Eric Douglas <e.d.programmer@gmail.com> - 2017-06-29 13:49 -0700
                Re: Eclipse Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-06-29 18:16 -0400
  Re: Eclipse Arne Vajhøj <arne@vajhoej.dk> - 2017-07-02 11:56 -0400

csiph-web