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

139
Views
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 answers
Answer question

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 Report

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 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!