https://kotlinlang.org logo
#announcements
Title
# announcements
s

santiago

10/26/2017, 9:02 PM
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

diesieben07

10/26/2017, 10:08 PM
Just annotate the property:
@Annotation val theField
s

santiago

10/26/2017, 10:13 PM
I have tried that. But when I do MyClass::theField.findAnnotation<Annotation>(), it returns null. MyClass::theField.annotations is also an empty list.
d

diesieben07

10/26/2017, 10:23 PM
Which annotation is it?
s

santiago

10/26/2017, 10:23 PM
In this case it is the @ColumnName annotation from JDBI.
d

diesieben07

10/26/2017, 10:27 PM
That annotation is a Java annotation declared to annotate either a field or a method. It cannot annotate the property itself.
s

santiago

10/26/2017, 10:28 PM
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

diesieben07

10/26/2017, 10:42 PM
Weird. I am seeing the same, that looks like a bug, but I am not sure.
s

santiago

10/26/2017, 10:45 PM
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.
2 Views