Scala

Scala

Made by DeepSource

Array comparison using conventional comparison operators SC-W1046

Bug risk
Critical

Using the conventional comparison operators such as == or != do not necessarily compare the contents of arrays. Rather, the said operators check if the entities on both sides refer to the same object or not. To put it in simpler terms, they check reference, not contents. To compare the contents of 2 Arrays, use sameElements.

Bad practice

val a = Array(1, 2)
val b = Array(1, 2)
val c = a

a == b // false!
a == c // true, because they both refer to same obj, i.e. `Array(1, 2)`

Recommended

val a = Array(1, 2)
val b = Array(1, 2)

a.sameElements(b)   // true