🐦 Kotlin
Advanced
How does Kotlin handle Java interoperability with nullable types?
Answer
When Kotlin calls Java code, Java types appear as platform types — indicated in the IDE with a ! suffix (e.g., String!). Platform types are neither nullable nor non-nullable in Kotlin's type system — the compiler does not enforce nullability for them, placing the responsibility on the developer. You can treat them as either nullable or non-nullable. To get proper nullability information, annotate Java code with @NotNull and @Nullable annotations (from JetBrains, Android, or JSR-305 packages) — Kotlin recognizes these and applies the corresponding nullability constraints, restoring compile-time null safety for Java APIs.
Previous
What is the buildList function in Kotlin?
Next
What is an object expression (anonymous object) in Kotlin?