Restricted mixed type equals() - in this case we genuinely assume here that ColorPoint of any color is not equal intrinsicly colorless Point even if they have got the same coordinates. However any class extending Point but not adding value component should be equal having the same coordinates. In that sense it is Liskov Substitution Principle compliant.
I present you FIXED version as original Tal Cohens did not even compile (!) and suffered by StackOverflowError
Drawback of Tal Cohen solution is that is not that "fail fast" as previous solutions, fields would be compared unnecessarily when subclass check is bound to fail.
Also see tal forums for discussion and different fixed version an alternatives.
|
|
|
|