Nullability Annotations

This Atom is Under Construction

When you’re working on a mixed Kotlin and Java project, you may or may not have the control over the Java code base.

When you use a Java library, you can’t modify the Java code, so you must work with platform types. The advice from previous atom works for this case: specify types explicitly to avoid subtle NPE errors.

If you control the Java code base, you can add annotations. @Nullable tells Kotlin to treat a Java type as nullable, while @NotNull tells Kotlin to treat a Java type as non-null:

End of sample. See for full early-access book.

Previous          Next

©2018 Mindview LLC. All Rights Reserved.