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

389
Vistas
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 Respuestas
Responde la pregunta

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