We can use reflection to get method names as follows:
object Foo { def bar(name:String, age:Int) = {} }
val foo = Foo.getClass
val methods = foo.getMethods.filter(_.getName.startsWith("b"))
methods.foreach(m => println(m.getName))
I now need to get the parameter types and names.
- Are the parameter names stored in the byte-code? If answer is yes, how to access them?
- If answer above is no, can we store the names somehow using annotations?
- Can someone given an example to read the types, and how to use them. I am interested only in functions having
Stringand/orArray[String]type parameters.
[EDIT:] Java version of the solution also ok.
[EDIT:] Annotations seems to be one way to do it. However, Scala annotation support is not that good. Related SO question.
If debugging info is present in the classes, it can be done as follows.
I am basically using Adam Paynter’s answer and copy-pasting the code from here after slight edit to get it to work in Scala.