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/extensions.md
+4-5Lines changed: 4 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,10 +4,9 @@ Kotlin _extensions_ let you extend a class or an interface with new functionalit
4
4
design patterns like _Decorator_. They are useful when working with third-party libraries you can't modify
5
5
directly. Once created, you call these extensions as if they were members of the original class or interface.
6
6
7
-
The most common forms of extensions are _extension functions_ and [_extension properties_](#extension-properties), which
8
-
are available in [companion objects](#companion-object-extensions) as well as classes and interfaces.
7
+
The most common forms of extensions are [_extension functions_](#extension-functions) and [_extension properties_](#extension-properties).
9
8
10
-
Extensions don't modify the classes or interfaces they extend. By defining an extension, you aren't inserting new members,
9
+
Importantly, extensions don't modify the classes or interfaces they extend. By defining an extension, you aren't inserting new members,
11
10
only making new functions callable or new properties accessible via special syntax.
12
11
13
12
## Receivers
@@ -156,8 +155,8 @@ For more information about generics, see [generic functions](generics.md).
156
155
### Nullable receivers
157
156
158
157
You can define extension functions with a nullable receiver type, which allows you to call them on a variable
159
-
even if its value is null. When the receiver is `null`, `this` is also `null`. To avoid compiler errors, we recommend checking
160
-
`this == null`check inside the function body when defining an extension with a nullable receiver.
158
+
even if its value is null. When the receiver is `null`, `this` is also `null`. Make sure to handle nullability correctly
159
+
within your functions. For example, use `this == null`checks inside function bodies, [safe calls `?.`](null-safety.md#safe-call-operator), or the [Elvis operator `?:`](null-safety.md#elvis-operator).
161
160
162
161
In this example, you can call the `.toString()` function without checking for `null` because the check already happens inside
0 commit comments