1

I have an annotation like following:

@Arg
internal var stringArg1: String? = null
@Arg
internal var stringArg2: String = "default value"

And I iterate over all of my annotated classes variables like following:

for (e in annotatedElement.enclosedElements) {
    if (e.getAnnotation(Arg::class.java) != null) {
        val defaultValue = ??? 
    }
}

Question:

Is it possible to get the default value of an annotated variable? In my example I want to retrieve null and "default value" for my two variables.

Bartek Lipinski
  • 30,698
  • 10
  • 94
  • 132
prom85
  • 16,896
  • 17
  • 122
  • 242

1 Answers1

1

No, it's not possible.

Default values would have to be stored in Kotlin metadata for you to access them in your annotation processor (and they are not stored there).

You can see some details about that in the Kotlin repository:

docs

Bartek Lipinski
  • 30,698
  • 10
  • 94
  • 132