Bridge.kt
- 1fun titleFrom(view: TextView): String {
- 2 return view.text?.toString().orEmpty()
- 3}
Bridge.kt
Calling Java without pretending
Most of the Android SDK was written in Java. Kotlin calls it directly. Annotations such as @Nullable and @NotNull help the compiler, and where they are missing the type is a platform type.
A Kotlin data class is not automatically a Java bean. @JvmStatic, @JvmOverloads, and @JvmField exist for the cases where Java code has to call back in a familiar shape.
The lesson stops at the boundary: check null, keep the Kotlin side typed, and do not hide a Java null inside a non-null property.