Versions Compared

Key

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

Arrays do not override the Object.equals() method; rather, the implementation of the equals() method compares array references rather than their contents. To compare the contents of two arrays, use the two-argument Arrays.equals() method instead. When intentionally testing reference equality, use the reference equality operators, == and !=. Inappropriate use of the equals() method can lead to unexpected results. Consequently, programs must reserve use of the array equality operators == and != for testing whether two array references specifically refer to the same array object, and are required to use the two-argument Arrays.equals() method for all other cases.

This rule is a specialization of EXP01-J. Do not confuse abstract object equality with reference equality.

Noncompliant Code Example

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="4caeb3cc725aa48d-b6909f81-48274299-98f4bd0a-63ca0bd2cfed37227d34d112"><ac:plain-text-body><![CDATA[

[[API 2006

AA. Bibliography#API 06]]

[Class Arrays

http://download.oracle.com/javase/6/docs/api/java/util/Arrays.html]

]]></ac:plain-text-body></ac:structured-macro>

...