• By default any sort of Java reference is a platform type in Kotlin.
  • Since Java does not allow for expressing type-safety, the null-checks for Java references are relaxed in Kotlin
  • This affects Kotlin’s sought-after null-safety feature
  • However, the null-checks can be made strict  by adding the -Xjsr305 compiler flag with the strict options
// build.gradle.kts
 
tasks.withType<KotlinCompile> {
  kotlinOptions {
    freeCompilerArgs += "-Xjsr305=strict"
  }
}

Refs

  1. https://kotlinlang.org/docs/java-interop.html#null-safety-and-platform-types
  2. https://spring.io/guides/tutorials/spring-boot-kotlin