I know about two:
@deprecated("use blabla instead")
is used to add an explanation to the warning output by the compiler when the annotated definition is used in client code.@implicitNotFound(msg = "more meaningful explanation")
is used to output an additional error message whenever an implicit of the type of the annotated definition cannot be found. Looking at CanBuildFrom
, msg can contain placeholders of the type ${A}
if A
is the name of a type parameter of the annotated type, which is filled in by the compiler with the actual expected type, e.g.:
@implicitNotFound(msg = "Cannot construct a collection of type ${To} with elements of type ${Elem} based on a collection of type ${To}.")
trait CanBuildFrom[-From, -Elem, +To] { ... }
Are there any other such annotations?
There is @migration
, which is used with -Xmigration
to indicate semantic changes in methods from one version to another, in helping port code between versions.
@migration(2, 8, "As of 2.8, keys returns Iterable[A] rather than Iterator[A].")
There is @tailrec, which makes the compiler output an error if tail call optimization cannot be applied to the annotated method.
As of Scala 2.9, there's also @deprecatedName
: “An annotation that designates the name of the parameter to which it is applied as deprecated. Using that name in a named argument generates a deprecation warning.”
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With