-1

Implimentation of Annotation

@Target(AnnotationTarget.PROPERTY)
@Retention(AnnotationRetention.RUNTIME)
annotation class Returnable

Dummy Data class

data class DataClass(
    val property: String
    @Returnable
    val annotatedProperty: String
)

Java Reflections filtering doesn't work

this::class.memberProperties
        .filter{ it.annotations.map { ann -> ann.annotationClass }.contains(Returnable::class)}
Ihar Sadounikau
  • 741
  • 6
  • 20

1 Answers1

1

Kotlin annotation isn't the same as Java annotations. So work with Kotlin reflection requires a bit different way compare to classic java. Here you can find a way of filtering properties of Kotlin data class by Kotlin annotations

DataClass("false","true")::class.members.filter {
     it.findAnnotation<Returnable>() != null
}
Ihar Sadounikau
  • 741
  • 6
  • 20