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

145
Vistas
Kotlin short literal pre/postfix?

The following code throws an error that == cannot be applied between int and short.

if(shortVal == 3)

Does Kotlin have a way to denote that a numeric literal is a short, something like 3S?

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

0

There is no functionality like that in the standard library, as far as I know. But you're still free to implement a functionality like that on your own, e.g. using Kotlin's extension properties.

val Int.s: Short
    get() = toShort()

val i: Int = 3
val s: Short = 3.s
over 4 years ago · Santiago Trujillo Denunciar

0

You could also create an infix function instead of ==. I called it eq

infix fun Short.eq(i: Int): Boolean = this == i.toShort()

And you can use it like this

if(shortVal eq 3)
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