Vitali Plagov
09/28/2021, 10:15 AMobject
with constants defined as const val
. I want to get a list of all constants available in this object. Is there a convenient way to get them? I tried with reflection: MyObjectWithConstant::class.declaredMemberProperties
Joffrey
09/28/2021, 10:17 AMephemient
09/28/2021, 10:27 AMconst val
, so if that's important to you, you'll need to use other approaches like reflection or codegenVitali Plagov
09/28/2021, 10:29 AMJoffrey
09/28/2021, 10:30 AMVitali Plagov
09/28/2021, 10:31 AMconst val
is so importantephemient
09/28/2021, 3:52 PMMyObjectWithConstant::class.declaredMemberProperties.filter { it.isConst }.associate { it.name to it.call() }
but does have a downside of being limited to JVM onlyprivate
so nobody else can mess with it. I'd probably choose to do something with kapt/ksp to generate a table of constants at compile-time if I had to (it would work with const
too)