Diese Antwort auf Scala 2.8 basiert. @tailrec:
// Will be visible to the Scala compiler, but not in the class file nor at runtime.
// Like RetentionPolicy.SOURCE
final class MyAnnotation extends StaticAnnotation
// Will be visible stored in the annotated class, but not retained at runtime.
// This is an implementation restriction, the design is supposed to support
// RetentionPolicy.RUNTIME
final class MyAnnotation extends ClassfileAnnotation
Für weitere Informationen, Kapitel 11 "User Defined Anmerkungen" in dem Scala Reference Siehe zum Beispiel sehen.
UPDATE Der Compiler Warnung sagt es am besten:
>cat test.scala
final class MyAnnotation extends scala.ClassfileAnnotation
@MyAnnotation
class Bar
>scalac test.scala
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.
final class MyAnnotation extends scala.ClassfileAnnotation
Discussion
Ich frage mich, ob es das wirklich wert ist? Anmerkung Klassen neigen dazu, eher klein zu sein, so dass es keinen wirklichen Vorteil gibt, sie in Scala zu schreiben. Genau wie Enums schreiben sie Java und machen damit fertig. – Martin