Const val in both code and annotations


Can I write something like this?

 const val path = "some/path"
 @SomeAnnotation(path = path)
 class Foobar


Apparently, you can.

I just tried this and it compiled OK:

const val PATH = "somePath"

annotation class SomeAnnotation(val path: String)

@SomeAnnotation(path = PATH)
class Foobar

Have you had a case where it didn’t work?


Thanks, @alanfo
I had troubles adding kapt to my project, now I did it, and it turned out this works