You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/topics/operator-overloading.md
+6-2Lines changed: 6 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -182,8 +182,12 @@ which can be overridden to provide custom equality check implementation. Any oth
182
182
>
183
183
{style="note"}
184
184
185
-
The `==` operation is special: it is translated to a complex expression that screens for `null`'s.
186
-
`null == null` is always true, and `x == null` for a non-null `x` is always false and won't invoke `x.equals()`.
185
+
The `==` operation translates `a == b` to `a?.equals(b) ?: (b === null)`, which safely handles comparisons involving `null` values.
186
+
The behavior of the comparison depends on the nullability of the values being compared:
187
+
188
+
* If `a` is `null`, the comparison returns `true` only if `b` is also `null`, and no function is called.
189
+
* If `a` is a nullable type and isn't `null` at runtime, the compiler calls `a.equals(b)`, even if `b` is `null`.
190
+
* If `a` is a non-nullable type and `b` is known to be `null`, the compiler replaces the comparison with `false` at compile time and skips the function call.
0 commit comments