We know that Kotlin requires us to explicitly define references that can hold null values. Java on the other hand is much more lenient about nullability, so we may wonder how Kotlin handles types coming from Java (basically the whole Android SDK and libraries written in Java). Whenever possible, the Kotlin compiler will determine type nullability from the code and represent types as actual nullable or non-nullable types using nullability annotations.
The Kotlin compiler supports several flavors of nullability annotations, including:
- Android (com.android.annotations and android.support.annotations)
- JetBrains (@Nullable and @NotNull from the org.jetbrains.annotations package)
- JSR-305 (Javax.annotation)