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

回眸只為那壹抹淺笑 提交于 2019-12-01 00:35:24

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!