Skip to content

Commit f3e5341

Browse files
committed
update: implementing comments from Nikita
1 parent c80bd41 commit f3e5341

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

docs/topics/operator-overloading.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,15 @@ For the assignment operations, for example `a += b`, the compiler performs the f
176176
| `a != b` | `!(a?.equals(b) ?: (b === null))` |
177177

178178
These operators only work with the function [`equals(other: Any?): Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/equals.html),
179-
which can be overridden to provide custom equality check implementation. Any other function with the same name (like `equals(other: Foo)`) will not be called.
179+
which you can override to provide a custom equality check implementation.
180+
Any other function with the same name (like `equals(other: Foo)`) is ignored.
180181

181-
> `===` and `!==` (identity checks) are not overloadable, so no conventions exist for them.
182+
> `===` and `!==` (identity checks) aren't overloadable, so no conventions exist for them.
182183
>
183184
{style="note"}
184185

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.
186+
Kotlin calls `.equals()` when neither operand is the `null` literal and the comparison isn’t between two floating-point types.
187+
Otherwise, `===` is used for `null` literal checks, and non-null floating-point values are compared by numeric value.
191188

192189
### Comparison operators
193190

0 commit comments

Comments
 (0)