In Android Studio, I see the following auto-complete suggestion:
Why is Intent marked as Intent! (note the exclamation mark)? I guess that means non-nullable, but aren't Kotlin variables non-nullable by default so isn't this superfluous?
In Android Studio, I see the following auto-complete suggestion:
Why is Intent marked as Intent! (note the exclamation mark)? I guess that means non-nullable, but aren't Kotlin variables non-nullable by default so isn't this superfluous?
!
means it's maybe nullable and maybe not, but the Java code didn't specify nullability (with annotations). With such parameters, Kotlin will not force you to pass a non-nullable reference, and it's up to you to look at the documentation for the method to see if it's safe to pass null. If the documentation doesn't mention it, you should assume null values are not safe. In this particular case, it is not safe to pass a null Intent, though I don't know if it throws NullPointerException or ActivityNotFoundException because the documentation doesn't mention it.
If I had to guess, they chose not to add the nullability notation for the Intent argument to avoid breaking old code, since they didn't explicitly forbid it before they started adding nullability notations to the AOSP.
See here for the Kotlin documentation about this notation.