All code in my posts, unless a source is explicitly mentioned, is my own.
All code in my posts, unless a source is explicitly mentioned, is my own.
All code in my posts, unless a source is explicitly mentioned, is my own.
------------------------
Bob
SCJP - 86% - June 11, 2009
Bob Ruth wrote:I just took the following at face value:
K & B 5.0, pg 527
First, be sure that the object being tested is of the correct type! It comes in polymorphically as type Object, so you need to do an instanceof test on it. Having two objects of different class types be considered equal is usually not a good idea, but that's a design issue we won't go into here. Besides, you'd have to do the instanceof test just to be sure that you could cast the object argument to the correct type so that you can access it's methods or variables in order to actually do the comparison. Remember, if the object doesn't pass the instanceof test, then you'll get a runtime ClassCastException.
Of course, I know that you can code around just about anything... but this demonstrates to me that there is a reason for adhering to that policy.
All code in my posts, unless a source is explicitly mentioned, is my own.
Having two objects of different class types be considered equal is usually not a good idea, but that's a design issue
Henry Wong wrote:Try this...
And of course, an ArrayList is NOT an instanceof LinkedList.
Henry
All code in my posts, unless a source is explicitly mentioned, is my own.