Skip to content

Don't use instanceOf to check equality#2

Open
martinchaves wants to merge 2 commits into
jiayun:masterfrom
martinchaves:master
Open

Don't use instanceOf to check equality#2
martinchaves wants to merge 2 commits into
jiayun:masterfrom
martinchaves:master

Conversation

@martinchaves
Copy link
Copy Markdown

By equals contract the equals method must be symmetric, a.equals(b) must be true only if b.equals(a) is true.
If instanceOf operator is used then a superclass can be "equals" to a subclass (superclass.equals(subclass)), but the inverse always return false, because "subclass instanceOf superclass" is always false.

BTW: Great work!

Gerardo Martín Chaves added 2 commits November 22, 2012 11:56
By equals contract the equals method must be symmetric. This means that a.equals(b) must be true if and only if b.equals(a) is true.
Using instanceOf doesn't grant this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant