Skip to content

Commit 14576d7

Browse files
committed
Alejandro review
1 parent edef763 commit 14576d7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

docs/topics/typecasts.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ To convert the type of an object in Kotlin to another type is called **casting**
101101

102102
In some cases, the compiler automatically casts objects for you. This is called smart-casting.
103103

104-
If you need to explicitly cast a type, use `as?` or `as` [cast operators](#cast-operators).
104+
If you need to explicitly cast a type, use `as?` or `as` [cast operators](#safe-nullable-cast-operator).
105105

106106
### Smart casts
107107

108-
The compiler tracks the type checks and [explicit casts](#unsafe-cast-operator) for immutable
109-
values and inserts implicit (safe) casts automatically when necessary:
108+
The compiler tracks the type checks and [explicit casts](#safe-nullable-cast-operator) for immutable
109+
values and inserts implicit (safe) casts automatically:
110110

111111
```kotlin
112112
fun logMessage(data: Any) {
@@ -412,7 +412,7 @@ Smart casts can be used in the following conditions:
412412

413413
Kotlin has two cast operators: `as` and `as?`. You can use both to cast, but they have different behaviors.
414414

415-
If a cast fails with the `as` operator, the compiler throws a `ClassCastException`. That's why it's also called the **unsafe** operator.
415+
If a cast fails with the `as` operator, a `ClassCastException` is thrown at runtime. That's why it's also called the **unsafe** operator.
416416
You can use `as` when casting to a non-null type:
417417

418418
```kotlin
@@ -452,7 +452,7 @@ fun main() {
452452
```
453453
{kotlin-runnable="true" kotlin-min-compiler-version="2.0" id="kotlin-safe-cast-operator"}
454454

455-
#### Cast nullable types
455+
#### Nullable types
456456

457457
To cast a nullable type safely, use the `as?` operator to prevent triggering a `ClassCastException` if the cast fails.
458458

@@ -526,7 +526,7 @@ In this example, when the `printAnimalInfo()` function is called with a `Dog` in
526526
to `Animal` because that's the expected parameter type. Since the actual object is still a `Dog` instance, the compiler dynamically
527527
resolves the `makeSound()` function from the `Dog` class, printing `"Dog says woof!"`.
528528

529-
You'll often see upcasting in Kotlin APIs where behavior depends on an abstract type. It's also common in Jetpack Compose
529+
You'll often see explicit upcasting in Kotlin APIs where behavior depends on an abstract type. It's also common in Jetpack Compose
530530
and UI toolkits, which typically treat all UI elements as supertypes and later operate on specific subclasses:
531531

532532
```kotlin

0 commit comments

Comments
 (0)