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

390
Views
Difference between Enum.values() and enumValues() in kotlin

In the official document, I found enumValues() function.

I used enumValues() function, but I cannot find difference.

enum class RGB {
    RED, GREEN, BLUE
}

RGB.values().joinToString { it.name } // RED, GREEN, BLUE
enumValues<RGB>().joinToString { it.name } // RED, GREEN, BLUE

What difference between enumValues() and Enum.values()?

Is it a function for platforms other than JVM? Or are there other use cases?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The problem with values() is that it only exists on each concrete enum class, and you can't call it on a generic enum to get its values, which is quite useful in some cases. Taking just the simplest example of wanting to access all values in a String, enumValues lets you write a function like this:

inline fun <reified T: Enum<T>> getEnumValuesString(): String {
    // could call RGB.values(), but not T.values()
    // even with the generic constraint and reified generics

    // this works, however
    return enumValues<T>().joinToString()
}

Which can then be called with any enum class you've defined:

getEnumValuesString<RGB>()
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!