Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

146
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda