-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Android Development with Kotlin
By :
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:
com.android.annotations and android.support.annotations)@Nullable and @NotNull from the org.jetbrains.annotations package)Javax.annotation)We can find the full list in the Kotlin compiler source code (https://github.com/JetBrains/kotlin/blob/master/core/descriptor.loader.Java/src/org/jetbrains/kotlin/load/Java/JvmAnnotationNames.kt).
We have seen this previously in Activity's onCreate method, where the savedInstanceState...