Interview kitsBlog

Your dream job? Lets Git IT.
Interactive technical interview preparation platform designed for modern developers.

XGitHub

Platform

  • Categories

Resources

  • Blog
  • About the app
  • FAQ
  • Feedback

Legal

  • Privacy Policy
  • Terms of Service

© 2026 LetsGit.IT. All rights reserved.

LetsGit.IT/Categories/Kotlin
Kotlinhard

Java interop — what are platform types (`String!`) and why are they risky?

Tags
#interop#platform-types#nullability
Back to categoryPractice quiz

Answer

A platform type comes from Java where nullability is unknown, so Kotlin treats it as “nullable or non-null” (`String!`). If you treat it as non-null but it’s actually null, you can still get an NPE; prefer proper nullability annotations and safe handling.

Advanced answer

Deep dive

Platform types (`T!`) appear when Kotlin calls Java code that lacks nullability metadata. Kotlin can’t be sure whether the value can be null, so it lets you treat it as `T` or `T?` — at your risk.

Why it’s risky

If you treat it as non-null and Java returns null, you can still crash with an NPE.

How to mitigate

  • Add/enable nullability annotations in Java (`@Nullable`, `@NotNull`) and configure strictness.
  • In Kotlin, prefer defensive handling at boundaries (safe calls, `requireNotNull`, explicit `T?`).

Common pitfalls

  • Spreading platform types deep into Kotlin code (NPE surprises).
  • Assuming Kotlin’s compiler will protect you here (it can’t without metadata).

Related questions

Kotlin
Companion object vs top-level members: when would you use each?
#kotlin#companion#top-level