Inspectopedia 2026.1 Help

'hashCode()' called on array

Calling hashCode() on an array returns the identity hash code, not a hash based on the array's contents. This is almost never what you want.

To calculate the hash code for an array correctly, use:

  • contentHashCode() for linear arrays

  • contentDeepHashCode() for multidimensional arrays

Example:

fun main() { val a1 = arrayOf<Any>() val hashcode = a1.hashCode() // incorrect }
fun main() { val a1 = arrayOf<Any>() val hashcode = a1.contentHashCode() // correct }

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

KotlinArrayHashCode
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Kotlin | Probable bugs

Inspection ID: KotlinArrayHashCode

Suppressing Inspection

You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:

//noinspection KotlinArrayHashCode

More detailed instructions as well as other ways and options that you have can be found in the product documentation:

Inspection Details

By default bundled with:

IntelliJ IDEA 2026.1, Qodana for JVM 2026.1,

Last modified: 31 March 2026