vendredi 25 octobre 2019

Getting a list of annotated functions in Kotlin using reflection

I am new to Kotlin and I want to do the following:

  1. Annotate some functions with an annotation e.g "Executable"

  2. At runtime, get all the functions with this annotation

  3. Inspect a property on the annotation and if it matches a condition, invoke the function

I have the following code

annotation class Executable(val name : String)

@Executable("doSomething")
fun stepDoSomething (param1 : String) {
    println("I am a step that does something! I print $param1")
}

However, I am unclear on how to retrieve all functions with the Executable annotation at runtime and inspect them.

Thank you for your help!





Aucun commentaire:

Enregistrer un commentaire