Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Wiki Markup
Do not violate any of these five conditions while overriding the {{equals}} method. Mistakes due to the first postulate are quite infrequent; it is thus omitted from this discussion. The second and third conditions are highlighted. The rule for consistency implies that mutable objects may not satisfy the {{equals}} contract. It is good practice to avoid defining {{equals()}} implementations so as to use unreliable sources such as IP addresses \[[Bloch 08|AA. Java References#Bloch 08]\] and caches. The final condition about the comparison with {{null}} is typically violated when the {{equals()}} code throws an exception instead of returning {{false}}. Since this does not constitute a security vulnerability, it is beyond the scope of this discussion.  

Noncompliant Code Example

...