Implimentation of Annotation

annotation class Returnable

Dummy Data class

data class DataClass(
    val property: String
    val annotatedProperty: String

Java Reflections filtering doesn't work

        .filter{ { ann -> ann.annotationClass }.contains(Returnable::class)}

1 Answers

Ihar Sadounikau On Best Solutions

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