Given the following object
object functions {
type MyOutput = String
def f1: MyOutput = "res1"
def f2: MyOutput = "res2"
def f3(foo: String): Boolean = foo.equals("bar")
def f4(in:String): MyOutput = in+"res4"
}
Is it possible to call all methods on this object, which the returned type is of MyOutput type?
Currenly I tried to use reflection for this, but had no luck with it.
import scala.reflect.runtime.universe._
val m = runtimeMirror(getClass.getClassLoader)
val instanceMirror = m.reflect(typeOf[functions.type])
val classSymbol = m.classSymbol(functions.getClass)
val methods = classSymbol.info.members.filter(_.isMethod)
methods.foreach({
method =>
if (method.info.resultType.toString.contains("MyOutput")) {
println(method.name.toString)
val methodm = instanceMirror.reflectMethod(method.asMethod)
methodm()
}
})
This is the error
scala.ScalaReflectionException: expected a member of class UniqueSingleType, you provided method