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 annotations like tailrec
, switch
, elidable
, and so on. So I defined some annotations as them do:
class A extends StaticAnnotation
@A
class X {
@A
def aa() {}
}
Then I write a test:
object Main {
def main(args: Array[String]) {
val x = new X
println(x.getClass.getAnnotations.length)
x.getClass.getAnnotations map { println }
}
}
It prints some strange messages:
1
@scala.reflect.ScalaSignature(bytes=u1" !1* 1!AbCaE
9"a!Q!! 1gn!!.<b iBPE*,7
Ii#)1oY1mC&1'G.Y(cUGCa#=S:LGO/AA!A 1mI!)
Seems I can't get the annotation aaa.A
.
How can I create annotations in Scala correctly? And how to use and get them?