Implementation of instance testing in Java, C++, C#

Posted by Jake on Programmers See other posts from Programmers or by Jake
Published on 2014-08-18T02:27:34Z Indexed on 2014/08/18 16:44 UTC
Read the original article Hit count: 300

Filed under:
|
|
|

For curiosity purposes as well as understanding what they entail in a program, I'm curious as to how instance testing (instanceof/is/using dynamic_cast in c++) works. I've tried to google it (particularly for java) but the only pages that come up are tutorials on how to use the operator.

How do the implementations vary across those langauges? How do they treat classes with identical signatures?

Also, it's been drilled into my head that using instance testing is a mark of bad design. Why exactly is this? When is that applicable, instanceof should still be used in methods like .equals() and such right?

I was also thinking of this in the context of exception handling, again particularly in Java. When you have mutliple catch statements, how does that work? Is that instance testing or is it just resolved during compilation where each thrown exception would go to?

© Programmers or respective owner

Related posts about java

Related posts about c#