There is a bit of inconsistency from my level of understanding. Let’s say we have code interop with Java, assuming MyJavaClass.getNullString is a static method that returns null:
val s1: String = null // Does not compile, s1 is not nullable val s2: String = MyJavaClass.getNullString() // Compiles, throws IllegalStateException at runtime
I think it doesn’t make sense to let the second line here to compile. It will be more reasonable to force nullability on a value returned from Java.
Then handling it like this if you don’t want it be nullable:
val s2: String = MyJavaClass.getNullString() ?: ""