Reputation: 17818
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.
Upvotes: 1
Views: 790
Reputation: 31438
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:
Upvotes: 1