How to get annotations from a property

hi, I use annotations to attach type info to property and I thought below code should work, but it didn’t.

@Target(AnnotationTarget.PROPERTY)
@Retention(AnnotationRetention.SOURCE)
annotation class embeddable(val entityType: KClass<*>)

data class Foo(val id: String, @embeddable(Bar::class) val bars: List<Bar>)
data class Bar(val id: String)

@OptIn(ExperimentalStdlibApi::class)
fun main() {
    val foo = Foo("f1", listOf(Bar("b1"), Bar("b2")))
    foo::class.memberProperties.forEach { println("${it.name}:${it.annotations}") }
}

It prints

bars:[]
id:[]

Do I miss anything?

As its name suggests, annotations with AnnotationRetention.SOURCE retention are available in the source code only and are removed when compiling. Use AnnotationRetention.RUNTIME instead.

Aha, thanks @broot