• 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

Question about instanceof operator....

 
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it valid to use this with interfaces?

Will (someObject instanceof someInterface) return true if someObject implements SomeInterface???

What about (superInterface instanceof childInterface)?

Will that return true if the object superInterface which is Identified as implementing SuperInterface and is actually implementing ChildInterface which extends SuperInterface.

I hope that made sense.

-Tad
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand your first question, and the answer is "yes", instanceof does the right thing if you ask if an object's class implements a given interface.

Your second question is harder to follow, so I will let you answer it for yourself, armed with the knowledge that instanceof X will return true whenever a cast to X would succeed.
 
Tad Dicks
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I was writing that I came to the conclusion that if the answer to the first question is yes then the answer to the second should be yes too as its the same question (kind of).


-Tad
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic