What does the exclamation mark mean in Kotlin? (Single exclamation mark)
Hello, colleagues! I recently started learning Kotlin after Java, and one thing confuses me. In some places in the code, I see a single exclamation mark after a data type, for example, `String!` or `List!`. I understand that Kotlin strictly distinguishes between nullable (`String?`) and non-null (`String`) types, but what is `String!`? I haven't found this in the official documentation.
Here's an example from my project where I use a Java library:
```kotlin
// Java code
public class JavaClass {
public static String getString() {
return null; // can return null
}
}
// Kotlin code
fun main() {
val result: String! = JavaClass.getString() // IDE shows String!
println(result.length) // Here I expect a compilation error, but there is none
}
```
The IDE (IntelliJ IDEA) shows the type
No answers yet.
Log in to leave an answer