Careeroza
Platform Types and Nullability
String!
Java does not say whether a return value can be null. Kotlin shows such values as platform types (String! in IDE hints): you may treat them as nullable or non-null, and Kotlin trusts you. If you guess wrong, you get a NullPointerException at the assignment, just like in Java.
Example
System.getProperty returns null for a missing key. Declaring the result as String? is safe.
fun main() {
val home: String? = System.getProperty("app.home") // treat as nullable
println("app.home = ${home ?: "not set, using /opt/app"}")
val javaVersion: String = System.getProperty("java.specification.version")
println("Java spec version is not blank: ${javaVersion.isNotBlank()}")
}Output
app.home = not set, using /opt/app Java spec version is not blank: true
Wrong Guess
Example
Declaring a platform value as non-null when it is actually null fails immediately with a clear message.
fun main() {
println("Reading config...")
val token: String = System.getProperty("api.token") // null in Java!
println("Token length: ${token.length}")
}Output
Reading config... Exception: java.lang.NullPointerException: getProperty(...) must not be null
Tip: Java code annotated with @Nullable/@NonNull (JetBrains, AndroidX, JSpecify, jakarta.annotation) gives Kotlin real nullable/non-null types instead of platform types. Annotate your Java APIs.