Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

295
Views
¿Cómo hacer cumplir los controles de anotación de seguridad nula en kotlin?

Considere este ejemplo:

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

compila sin ninguna advertencia (con cli kotlinc e IntelliJ) y lanza en tiempo de ejecución:

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

Traté de construirlo de diferentes maneras de acuerdo con documentos como este:

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

La anotación parece estar allí (como se ve en IntelliJ):

Anotación @NotNull en el constructor BigDecimal

Docs establece claramente que:

Los tipos de Java que tienen anotaciones de nulabilidad no se representan como tipos de plataforma, sino como tipos de Kotlin reales que aceptan nulos o que no son nulos.

¿Que me estoy perdiendo aqui?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

El argumento del constructor BigDecimal se trata como un tipo de plataforma porque el constructor en realidad no está anotado.

El IDE calcula sobre la marcha la anotación @NotNull examinando el código fuente. Si hace ctrl+clic en el constructor, irá al código fuente donde verá que no hay anotaciones.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!