Enforcing null safety
When calling from Kotlin into Java, there is less to consider regarding null safety. Because Kotlin has the more strict type system, the Kotlin code will generally have more information available regarding properties and variables. This does mean that once we make a call over into Java, we may lose some of that type information, but, like we saw before, there are things we can do in Java to help preserve that type information in some situations, such as making use of the@Nullable and @NonNull annotations.
As we've seen in this section, we can easily work with existing Java code from within our Kotlin code base. Existing Java classes may not have as much syntactic sugar available within the project as Kotlin code, but ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access