This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Agree. The post by Rob Prime tells you what you need to know. Remember that instanceof and similar only work for final classes; otherwise use the bit about this.getClass() and other.getClass(). Make sure to put the null test in first; if the other object is null then you assume it is different.
Originally posted by Campbell Ritchie: Remember that instanceof and similar only work for final classes; otherwise use the bit about this.getClass() and other.getClass().
If the itself method is final, you can use instanceof as well, as long as you hardcode the class. After all, if you compare two an object of class A with an object of a subclass of A and vice versa, both will check if the other is an instance of A. Both checks will return true, so symmetry has been achieved.