Skip to content

Files

Latest commit

 

History

History
25 lines (16 loc) · 712 Bytes

AvoidReferentialEquality.md

File metadata and controls

25 lines (16 loc) · 712 Bytes

Pattern: Use of referential equality

Issue: -

Description

Kotlin supports two types of equality: structural equality and referential equality. While there are use cases for both, checking for referential equality for some types (such as String or List) is likely not intentional and may case unexpected results.

Example of incorrect code:

val areEqual = "aString" === otherString
val areNotEqual = "aString" !== otherString

Example of correct code:

val areEqual = "aString" == otherString
val areNotEqual = "aString" != otherString

Further Reading