@al3c Actually, you are right
The following will output [true]
@Target(AnnotationTarget.FIELD)
@Retention(AnnotationRetention.RUNTIME)
annotation class ExampleAnnotation
class ExampleClass {
@ExampleAnnotation
val exampleProperty: String = ""
}
fun main() {
val clazz = ExampleClass::class.java
clazz.declaredFields.forEach { field ->
println(field.annotations.map { it is ExampleAnnotation })
}
}
I didn’t knew about this exact behavior.
In my defense, the question was about why it is needed to add @field:
and not is it always necessary.
But, I am so sorry for the false statement in my first answer