0

I have created a library that have the following 2 annotations:

@Target(ElementType.TYPE)
@Retention(AnnotationRetention.RUNTIME)
annotation class PushNotificationHandler

@Target(ElementType.METHOD)
@Retention(AnnotationRetention.RUNTIME)
annotation class PushNotificationDispatcher

And this the following class:

data class PushNotification(
    val sender: String,
    val body: String
)

There is an application that uses the library and have the following class

@PushNotificationHandler
class PushHandler {
    @PushNotificationDispatcher
    @Throws(IOException::class)
    fun dispatch(pushNotification: PushNotification) {
        ...
    }
}

I want to be able to find from the library all classes that are annotated with the PushNotificationHandler annotation and be able to call all methods that are annotated with the PushNotificationDispatcher annotation.

In short i'm trying to mimic Spring's RestController and PostMapping.

Karim H
  • 1,543
  • 10
  • 24
  • https://stackoverflow.com/questions/259140/scanning-java-annotations-at-runtime - check this – Sergiy Dakhniy Jul 13 '21 at 17:56
  • I'm researching about this a couple days ago. I guess in this case, once you have an annotation regarding runtime retention, you should implement a kind of processor to deal with the method invoking. I've found this [post](http://hauchee.blogspot.com/2015/10/annotation-processing-during-runtime.html) but I could not implemented or test it. If it work, please let me know if it helped you :) – Camilo Silva Jul 13 '21 at 17:58

0 Answers0