0
0
Kotlinprogramming~10 mins

Platform types from Java interop in Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to safely call a Java method that returns a platform type.

Kotlin
val length = javaString?.[1]
Drag options to blanks, or click blank then click option'
Alength
Blength()
Csize
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using length without parentheses causes an error.
2fill in blank
medium

Complete the code to safely handle a platform type that might be null.

Kotlin
val safeString: String = javaString[1] ?: "default"
Drag options to blanks, or click blank then click option'
A?.
B?
C!!
D?:
Attempts:
3 left
💡 Hint
Common Mistakes
Using ? or ?. does not assert non-null.
3fill in blank
hard

Fix the error in calling a Java method returning a platform type that might be null.

Kotlin
val length = javaString.[1]
Drag options to blanks, or click blank then click option'
Alength()!!
Blength()
Clength
Dlength!!
Attempts:
3 left
💡 Hint
Common Mistakes
Using length property causes error.
Forgetting !! leads to nullable type.
4fill in blank
hard

Fill both blanks to safely check and use a platform type from Java.

Kotlin
if (javaString [1] null) {
    val length = javaString.[2]()
}
Drag options to blanks, or click blank then click option'
A!=
B==
Clength
Attempts:
3 left
💡 Hint
Common Mistakes
Using == null instead of != null.
Using property length instead of method length().
5fill in blank
hard

Fill all three blanks to create a safe call chain with platform types from Java.

Kotlin
val length = javaString[1]?.[2]()?.let { it [3] 0 } ?: -1
Drag options to blanks, or click blank then click option'
A!!
Blength
C>
Attempts:
3 left
💡 Hint
Common Mistakes
Using property length without parentheses.
Missing null assertion operator.