What is the default target for an annotation when annotating property in Kotlin?

后端 未结 1 954
旧时难觅i
旧时难觅i 2021-01-06 13:01

Annotations in Kotlin can have different use-site targets as explained here: https://kotlinlang.org/docs/reference/annotations.html#annotation-use-site-targets

My qu

相关标签:
1条回答
  • The reference says:

    If you don’t specify a use-site target, the target is chosen according to the @Target annotation of the annotation being used. If there are multiple applicable targets, the first applicable target from the following list is used:

    • param (constructor parameter)
    • property (annotations with this target are not visible to Java)
    • field

    So if your annotation has @Target({ElementType.FIELD}), the annotation in Kotlin will target @field:.

    If it has no @Target specified, it may be used on any program element: the @property: target is also applicable and is chosen by default.

    0 讨论(0)
提交回复
热议问题