Null-safety
When calling Kotlin functions from Java, nobody prevents us from passing null as a non-null parameter. That’s why Kotlin generates runtime checks for all public functions that expect non-nulls. This way we get a NullPointerException in the Java code immediately.
Is this true for constructors, too?
Does the compiler generate a null-check for the parameter x in the following case?
class Example(val x: String)
Or do I have to enforce it with an explicit null-check for Java interoperability?
class Example(val x: String) {
init {
if (x == null) throw NullPointerException()
}
}