Const val in both code and annotations


#1

Hi
Can I write something like this?

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

#2

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?


#3

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