I'm confused. Since (a instanceof b) won't even compile unless you have compatible types on both sides, what use is it? I mean, I already have to know that a is declared as type b or as a child of type b, so... what's the magic of having an operator tell me? And if it's only telling me "yeah, it's been instantiated" or "no, it hasn't been", wouldn't (a != null) yield exactly the same information?
Originally, I thought instanceof would tell you IF a was a member of b or one of b's children, i.e. I expected:
Date a = new Date();
boolean b = (a instaceof String);
to result in b == false. But, this won't compile. (One would have to use aClassInstance.isAssignableFrom() to get that result.)
What am I missing? I know that there must be some good reason for the existence of instanceof!
TIA
-DG
Originally, I thought instanceof would tell you IF a was a member of b or one of b's children, i.e. I expected:
Date a = new Date();
boolean b = (a instaceof String);
to result in b == false. But, this won't compile. (One would have to use aClassInstance.isAssignableFrom() to get that result.)
What am I missing? I know that there must be some good reason for the existence of instanceof!
TIA
-DG