Is there any way to get an annotation onto a field...
# announcements
s
Is there any way to get an annotation onto a field in a data class such that when I do ThatDataClass::theField, I can call findAnnotation<Annotation>() on the KProperty and get the Annotation back? I am having trouble doing that, after doing @field:Annotation val theField.
d
Just annotate the property:
@Annotation val theField
s
I have tried that. But when I do MyClass::theField.findAnnotation<Annotation>(), it returns null. MyClass::theField.annotations is also an empty list.
d
Which annotation is it?
s
In this case it is the @ColumnName annotation from JDBI.
d
That annotation is a Java annotation declared to annotate either a field or a method. It cannot annotate the property itself.
s
I want to annotate the field, I just thought the KProperty for that field would have annotation information for the field.
Is there any way to get the annotation on a field?
I tried @field:ColumnName and @get:ColumnName as well, but I don’t see it on the field or the getter method.
d
Weird. I am seeing the same, that looks like a bug, but I am not sure.
s
I tried searching the bug database, but it proved difficult to find anything, the UI Was very confusing.
When I look at the generated bytecode, the annotation is present.