What is the role of type suffix "!" in a declaration

For example, in the Kotlin documentation for Android class Toast we have a function declared as

open static fun makeText(
    context: Context!, 
    text: CharSequence!, 
    duration: Int
): Toast!

What is the role of the exclamation point following the type names?

(Also, I was surprised to see the word static in a Kotlin function declaration.)

1 Like

Those are Platform Types. Simple answer is that makeText is a Java declaration that doesn’t have explicit nullability annotations, and so Toast! means that the type might be nullable, but it might not be. If you know that it’s not nullable, you can use it without null checks, but the compiler also won’t complain if you do use null checks.


Thank you for the clarification. I tried for about an hour to find this by searching the internet, the Kotlin web site, and Stack Overflow, but I could not formulate a query that gave reasonable results.