Sometimes I need to pass a string to an annotation, and I want to use for that the name of an Enum instance, or something directly derived from an Enum name, or a val constructor param to an Enum. Something that would effectively be a compile time constant therefore, like an Enum instance is considered a compile time constant.
However the compiler doesn’t consider it a compile time constant so I’m wondering if it’s possible to mark some read-only properties in an Enum as such with the const keyword:
enum class MyEnum {
E1, E2;
const val roleName : String
get() = "ROLE_" + name
}
class Foo {
@RolesAllowed(MyEnum.E1.roleName)
fun bar() {}
}
Could this be considered for a future enhancement to Kotlin?