File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Why Obejct == JComboBox legal? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why Obejct == JComboBox legal? " Watch "Why Obejct == JComboBox legal? " New topic

Why Obejct == JComboBox legal?

Zhixiong Pan
Ranch Hand

Joined: Jan 25, 2006
Posts: 239
Hi all,
Here is a legal expresion:

e here is an instance of ActionEvent, and getSource() returns an Object. hairCB is an instance of JComboBox. So is Object == JComboBox legal?

Sam Codean
Ranch Hand

Joined: Feb 26, 2006
Posts: 194
yes why not. The Expresssion is completely legal. It is comparing two references and that is what == has to do

-Sam Codean<br />SCJP 1.4 (98%)<br />SCJD 5.0 (87.5%)
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

please read the rules on display names. You can see the long version here.

The short version goes like this:
Display names must be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please fix your display name immediately, since accounts with invalid display anmes get deleted, often without warning.

Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

And after fixing your name, could you answer this one please ?
You're not going to copy/paste, are you ?

Comparing two references.
Does this code compile ?

[My Blog]
All roads lead to JavaRanch
Joni Salonen
Ranch Hand

Joined: Jan 07, 2006
Posts: 53
You can only compare objects that are in the same inheritance hierarchy. If by the compile-time types the compiler can see that the two variables can never be equal, it flags the comparison illegal.

If an object is an instance of A it can never be an instance of B. But an instance of Object can be an instance of ActionEvent:
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

Thank you very much.
I wish the person I was asking that could answer too,
but probably did not understand the concept
Sam Codean
Ranch Hand

Joined: Feb 26, 2006
Posts: 194
Hi Satou,
Sorry i was a bit busy so could not reply in time. Hmm.. Now that you have asked not to compile and give the answer, it is very tempting to do that and see.
I think the question is already answered so have nothing to say.
But can i know why this test for me?
I agree. Here's the link:
subject: Why Obejct == JComboBox legal?
jQuery in Action, 3rd edition