Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

291
Vistas
How to enforce null safety annotation checks in kotlin?

Consider this example:

import java.math.BigDecimal

fun main(args: Array<String>) {
  val s: String? = null
  BigDecimal(s)
}

it compiles without any warnings (with cli kotlinc and IntelliJ) and throws at runtime:

Exception in thread "main" java.lang.NullPointerException
    at java.math.BigDecimal.<init>(BigDecimal.java:809)
    ...

I tried to build it in different ways according to docs like so:

kotlinc \
 -Xnullability-annotations=@javax.annotation:strict \
 -Xnullability-annotations=@org.jetbrains.annotations:strict \
 -Xjsr305=strict \
Main.kt -d main.jar

Annotation seems to be there (as seen in IntelliJ):

@NotNull annotation in BigDecimal constructor

Docs clearly states that:

Java types that have nullability annotations are represented not as platform types, but as actual nullable or non-null Kotlin types.

What am I missing here?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The argument to the BigDecimal constructor is treated as a platform type because the constructor is not actually annotated.

The @NotNull annotation is calculated on-the-fly by the IDE by examining the source code. If you ctrl+click on the constructor, you will go to the source code where you will see there is no annotation.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda