https://kotlinlang.org logo
Title
e

edwardwongtl

11/20/2018, 7:26 AM
Is there a way to get `enum`’s
values
from a instance variable? e.g.
enum class Kind { Single, Double } 
class A(val a: Kind)

A().a /// from here get the type of a and get its enum class, then get enum.values?
r

rnpy

11/20/2018, 7:37 AM
I'd guess not without using reflection, seems to be a pretty weird thing to do
d

diesieben07

11/20/2018, 7:48 AM
On the JVM you can do
a.declaringClass.enumConstants
,
r

rnpy

11/20/2018, 8:03 AM
another reflection-free way that could potentially be used is using
enumValues
in an `inline fun`: https://pl.kotl.in/r1UnkBZRX
e

edwardwongtl

11/20/2018, 8:05 AM
Thanks a lot. Both works as what I trying to do.