vendredi 25 septembre 2020

How can I find Annotated methods in Scala/Java on Runtime

I want to use Runtime Reflection with Scala annotations (could also be a Java annoations if necessary, but I would prefer to limit pure Java code)

I want to implement something like:

/**
  print all methods that implement a specific annotation
*/
 def getAllAnnotated(): Unit {...}

For example, if I have:

class Foo {
    @printme
    def foo(args: A): R
    
    def oof(args: A): R
}
class Bar {
    @printme
    def bar(): Unit
}

The result of running getAllAnnotated() would be something like:

Foo.foo
Bar.bar

Note that I don't want to look in a specific class, but instead any available method





Aucun commentaire:

Enregistrer un commentaire