Finding field annotations using obj::class.declaredMemberProperties

In the following test, the field id of class TestData is marked with the annotation Foo. Why is the output of .annotations and .findAnnotation() empty though?

How can check if a field is annotated by a certain annotation?

I asked this as well on reflection - Finding field annotations using obj::class.declaredMemberProperties - Stack Overflow but got no answer. Is it the same bug as although I don’t have “use-site” annotations?

import kotlin.test.Test
import kotlin.reflect.full.declaredMemberProperties
import kotlin.reflect.full.findAnnotation
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue

class MissingAnnotationTest {

    annotation class Foo

    data class TestData(@Foo val id: Int)

    fun test() {
        val obj = TestData(123)
        val idProp = obj::class.declaredMemberProperties.first { == "id" }

        println("# property: " + idProp) // "val kotlin.Int"
        println("# annotations: " + idProp.annotations) // [] - but why?
        println("# findAnnotations<Foo>: " + idProp.findAnnotation<Foo>()) // null - but why?

        assertTrue(" kotlin.Int"))
        assertEquals(1, idProp.annotations.size, "Bug! No annotations found!")


The problem is that you are trying to get the annotation of the property. Kotlin’s property get compiled to a getter and a backing field on the JVM. If you try to get the annotations of the property, you don’t get the annotation of the underlying field. Your code would find the annotations if you changed the target from FIELD to property (I forgot how the enum is called exactly).
If you want the annotations of the backing field you have to get them from property.javaField.getAnnotation(

Thanks for the quick answer, now I understand the difference between fields, properties and member functions.