0
votes

In the Scala language specification, ยง6.14 Annotated Expressions:

An annotated expression e: @a1 ... @an attaches annotations a1, ..., an to the expression e.

While I can get annotations just fine on classes (and their member values and methods), I can't find a way to get the annotations on an expression at runtime.

Say I have val x = C(f1 = v1 : @a1, f2 = v2 : @a2), how do I get annotations @a1 and @a2 from x's fields? (where C is a case class and @aX may be custom annotations)

1
You should add some code of what you're doing. How do you get annotations for classes, what have you tried to get them for expressions? - laughedelic

1 Answers

0
votes

Using runtime reflection I don't believe you can access any expressions (except for annotation values and default parameter values; there may be something else I am overlooking) at all, and so you can't access any annotations on them.

You need C or C.apply to be a macro (or use a compiler plugin).