https://kotlinlang.org logo
Title
e

elect

05/10/2019, 10:27 AM
is there a way to conveniently save an enum type and then later retrieve all the name of that enums?
m

Marc Knaup

05/10/2019, 10:29 AM
If it's on the JVM use
val foo: KClass<Enum<*>>
and then
foo.java.enumConstants.map { it.name }
for the names.
e

elect

05/10/2019, 10:33 AM
how can I set
foo
?
m

Marc Knaup

05/10/2019, 10:33 AM
foo = MyEnum::class
e

elect

05/10/2019, 10:33 AM
that is, how to retrieve the
Kclass
I'm dummy, I was looking for
KClass
returning type, but
.class
doesnt show anything..
anyway, thanks Marc, it works flawness
👍 1
n

nkiesel

05/10/2019, 8:34 PM
or use
Enum.values()
enum class Foo { A, B, C }
val names =  Foo.values().map { it.name }
d

Dico

05/11/2019, 2:05 AM
enumValues<Foo>()