Skip to content
Commitwise
Menu

Platform type

A type from Java whose nullability Kotlin doesn't know, shown as String! and not checked by the compiler.

Definition

When Kotlin calls a Java method without nullability annotations, it can't tell whether the result may be null. It gives it a platform type (written String! in error messages) and lets you use it as either String or String?. If you treat it as non-null and Java returns null, you get a NullPointerException at runtime. Annotating the Java code (for example with JSpecify) turns platform types into real Kotlin types.

In practice

val name = javaUser.getDisplayName() followed by name.length compiles, but crashes when the Java method returns null.

Learn it in context

Lessons that use this term.

Related terms

Esc

Type to search the whole site.