The following code fails to compile (Output is not of type java.reflect.annotation.Annotation):
class Output(val name : String) extends Annotation
class Block {
def outputs {
for {
method <- this.getClass.getMethods
val a = method.getAnnotation(classOf[Output])
if a != null
} {
println(a.name)
}
}
}
class Arithmetic[T: Numeric](val A: Connector[T], val B: Connector[T]) extends Block {
@Output("Sum") def Sum = new Connector({ A.Value + B.Value })
@Output("Difference") def Diff = new Connector({ A.Value - B.Value })
@Output("Multiply") def Mul = new Connector({ A.Value * B.Value })
}
Is there any way to achieve runtime reflection on the annotated members?
It seems there is no way to achieve this in Scala (yet), and thus we should resort to using a Java class as such: