How to create annotations and get them in scala

前端 未结 5 2040
遥遥无期
遥遥无期 2020-12-08 16:25

I want to define some annotations and use them in Scala.

I looked into the source of Scala, found in scala.annotation package, there are some annotation

5条回答
  •  旧巷少年郎
    2020-12-08 16:43

    Could it have something to do with retention? I bet @tailrec is not included in the bytecode getting generated.

    If I try to extend ClassfileAnnotation (in order to have runtime retention), Scala tells me that it can't be done, and it has to be done in Java:

    ./test.scala:1: warning: implementation restriction: subclassing Classfile does not
    make your annotation visible at runtime.  If that is what
    you want, you must write the annotation class in Java.
    class A extends ClassfileAnnotation
          ^
    

提交回复
热议问题