【发布时间】:2014-03-21 17:19:23
【问题描述】:
当注解的参数是常量时,我成功了,比如:
@Annotation(2)
class AnnotatedClass
因为我可以通过以下方式获得宏的impl 中的值:
c.prefix.tree match {
case Apply(_, List(Literal(Constant(x)))) => x.toInt
}
但是当注释的参数不是常量时,我很困惑,比如:
object Obj {val n = 2}
@Annotation(Obj.n)
class AnnotatedClass
类似于this question中的错误启动,我可以再次匹配c.prefix.tree并提取名称Obj和n,但是我如何获得Obj.n的值?
【问题讨论】:
标签: scala annotations scala-macros