File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why Obejct == JComboBox legal? " Watch "Why Obejct == JComboBox legal? " New topic
Author

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?


SCJP 1.4 SCJD
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
Rancher

Joined: Mar 06, 2001
Posts: 13459

"Codean",
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.

thanks,
Dave.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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é
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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: http://aspose.com/file-tools
 
subject: Why Obejct == JComboBox legal?
 
Similar Threads
Interesting exception errors
Is this a legal Generic method definition ?
getSelectedItem() selects nothing
I doubt my garbage collection
Questio about castdown and ClassCastException (Certification)