Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #36770
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Eclipse |
| Date | 2017-06-29 16:34 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <oj3o1v$4oh$1@dont-email.me> (permalink) |
| References | (2 earlier) <5314f277-558b-43d1-8564-460ab8dab26a@googlegroups.com> <1b033cbe-4bc2-497f-9c93-e6e90b75f39b@googlegroups.com> <oj3cof$rbp$1@dont-email.me> <7dff7a25-5881-4ecb-a937-ab076082dfcd@googlegroups.com> <oj3ik3$c4n$1@dont-email.me> |
On 6/29/2017 2:58 PM, Martin Gregorie wrote:
> On Thu, 29 Jun 2017 11:08:26 -0700, Eric Douglas wrote:
>
>> On Thursday, June 29, 2017 at 1:22:13 PM UTC-4, Martin Gregorie wrote:
>>> On Thu, 29 Jun 2017 06:05:31 -0700, Eric Douglas wrote:
>>>
>>>> I have some different types of JComponent classes which implement
>>>> MyCustomInterface, and some JComponent which do not implement.
>>>> I have a class level variable defined as
>>>> ArrayList<MyCustomInterface>.
>>>>
>>> Shouldn't you be using the name of the class that implements the
>>> MyCustomInterface Interface rather than the name of the Interface?
>>>
>>>
>>>
>> That's why it's an interface. This array holds instances of several
>> different classes which implement the interface. They're all components
>> and they all require custom methods described in the interface. They
>> come from different classes, one might extend JTextField, another
>> extends JComboBox. I need to check this group of controls against
>> generic Component because I'm looking at the values from getComponent()
>> and getOppositeComponent() in a focusGained().
>
> Err, not really. An Interface defines a set of methods that must all be
> defined by an Interface but is not a Class anbd I think thats what is
> making Eclipse spit.
I doubt it (although my Eclipse experience is both little and
long ago). There's certainly nothing wrong from Java's point of
view: You can have a List<Runnable>, for example, and populate it
with instances of many different classes implementing Runnable,
none with a common ancestor other than Object.
> I think you need to declare the various classes that implement
> MyCustomInterface into subclasses of an (abstract?) superclass that
> extends JContainer which, at a quick glance, inherits the methods you
> mention from Container and Component.
Insisting on a particular inheritance hierarchy would be rather
limiting. To put it another way, what are interfaces *for*?
Now that we've learned where the Component reference comes from,
we can begin to speculate about what's going on: The O.P. has a
FocusListener, and wants to know whether the focus loser or focus
gainer (or perhaps both) is on a list of "special" instances that
all happen to implement MyCustomInterface. (We don't know whether
the list contains all MyCustomInterface implementations or only some
of them; but we know everything on the list is such an implementation.)
So he does `list.contains(event.getComponent())' and Eclipse alerts him
that the query is a trifle odd. It is in fact what he wants to do, but
Eclipse's eyebrows arch upward anyhow.
The question I'd ask is: What does the Component's presence in (or
absence from) the List<MyCustomInterface> tell us? That is, what will
the code do differently if the answer is "Here!" rather than "Huh?"
And -- here's the nub -- could the different action be handled more
smoothly by overriding focusGained() and/or focusLost() in the
MyCustomInterface implementation?
Maybe not, but that's the question I'd ask to start with.
--
esosman@comcast-dot-net.invalid
Thirteen hundred one days to go.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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