Sangmin Lee
05/11/2021, 7:39 AM// Annotation below
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.PROPERTY, AnnotationTarget.FIELD)
annotation class MyAnnotation
// Class
data class MyClass (
@MyAnnotation
var myProperty: String,
@MyAnnotation
var maybeICouldBeField: String
)
// Verification Code
val KProperties = MyClass::class.memberProperties
KProperties.forEach() {
println(it.annotations)
println(it?.javaField?.annotations)
}
In Verification Code, why I can’t see any annotation from javaField? 🤔thanksforallthefish
05/11/2021, 7:47 AM@field:MyAnnotation
should help. maybeRoukanken
05/11/2021, 7:48 AM@field:MyAnnotation
then it will be visible on Java field, but not in it.annotations
ephemient
05/11/2021, 7:48 AMIf there are multiple applicable targets, the first applicable target from the following list is used:
- param
- property
- field
Sangmin Lee
05/11/2021, 7:50 AMephemient
05/11/2021, 7:50 AM@param:
and not @field:
.Roukanken
05/11/2021, 7:51 AM