• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why Obejct == JComboBox legal?

 
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes why not. The Expresssion is completely legal. It is comparing two references and that is what == has to do
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?


 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic