# Confusion about @field:Annotation

**URL:** <https://discuss.kotlinlang.org/t/confusion-about-field-annotation/26272>\
**Category:** Support\
**Created:** [January 25, 2023, 9:53am UTC](https://discuss.kotlinlang.org/t/confusion-about-field-annotation/26272 "2023-01-25T09:53:28Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![LSafer](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/lsafer/32/9366_2.png) [@LSafer](https://discuss.kotlinlang.org/u/LSafer)\
**Post date:** [January 26, 2023, 10:55am UTC](https://discuss.kotlinlang.org/t/confusion-about-field-annotation/26272/5 "2023-01-26T10:55:01Z")

</div>

@al3c Actually, you are right 😗

> [@al3c](#):
>
> If both `property` and `field` are valid targets for the annotation, the `property` is annotated, Java will hence see an annotation on the getter.

The following will output `[true]`

```kotlin
@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

---

_[View the full topic](https://discuss.kotlinlang.org/t/confusion-about-field-annotation/26272)._
