Skip to content

Commit a587a1a

Browse files
chore: fix the runnable sample codes
1 parent 81f0a97 commit a587a1a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

docs/topics/null-safety.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ For example, the [`.toString()`](https://kotlinlang.org/api/latest/jvm/stdlib/ko
331331
can be called on a nullable receiver. When invoked on a `null` value, it safely returns the string `"null"` without throwing an exception:
332332

333333
```kotlin
334-
// SampleStart
334+
//sampleStart
335335
fun main() {
336336
// Assigns null to a nullable Person object stored in the person variable
337337
val person: Person? = null
@@ -343,7 +343,7 @@ fun main() {
343343

344344
// Defines a simple Person class
345345
data class Person(val name: String)
346-
// SampleEnd
346+
//sampleEnd
347347
```
348348
{kotlin-runnable="true"}
349349

@@ -353,7 +353,7 @@ If you expect the `.toString()` function to return a nullable string (either a s
353353
The `?.` operator calls `.toString()` only if the object is not `null`, otherwise it returns `null`:
354354

355355
```kotlin
356-
// SampleStart
356+
//sampleStart
357357
fun main() {
358358
// Assigns a nullable Person object to a variable
359359
val person1: Person? = null
@@ -368,7 +368,7 @@ fun main() {
368368

369369
// Defines a Person class
370370
data class Person(val name: String)
371-
// SampleEnd
371+
//sampleEnd
372372
```
373373
{kotlin-runnable="true"}
374374

@@ -407,7 +407,7 @@ You can use the `as?` operator for safe casts. It tries to cast a value to the s
407407

408408
```kotlin
409409
fun main() {
410-
// SampleStart
410+
//sampleStart
411411
// Declares a variable of type Any, which can hold any type of value
412412
val a: Any = "Hello, Kotlin!"
413413

@@ -420,7 +420,7 @@ fun main() {
420420
// null
421421
println(aString)
422422
// "Hello, Kotlin!"
423-
// SampleEnd
423+
//sampleEnd
424424
}
425425
```
426426
{kotlin-runnable="true"}
@@ -435,7 +435,7 @@ the `filterNotNull()` function:
435435

436436
```kotlin
437437
fun main() {
438-
// SampleStart
438+
//sampleStart
439439
// Declares a list containing some null and non-null integer values
440440
val nullableList: List<Int?> = listOf(1, 2, null, 4)
441441

@@ -444,7 +444,7 @@ fun main() {
444444

445445
println(intList)
446446
// [1, 2, 4]
447-
// SampleEnd
447+
//sampleEnd
448448
}
449449
```
450450
{kotlin-runnable="true"}

0 commit comments

Comments
 (0)