Scala categorizes annotations as
Annotations always start with the
@ symbol, and they do not change the action of a compiled program. Since Scala integrates with Java’s annotations system, it is easier to call built-in annotations from Java.
We can only apply an annotation clause to the first definition or declaration. After that, the order of annotation clauses doesn’t matter. Thus, more than one annotation clause can precede a definition and declaration.
Users can either define their own annotations (i.e., User-defined annotations) or use the built-in annotations from the Scala library.
Some built-in annotations in Scala include:
@deprecated: This indicates that a declaration is obsolete and has been replaced by a newer form.
@unchecked: This attribute suppresses any warnings about non-exhaustive pattern matches which would otherwise be emitted.
@transient: This annotation is used to make a field non-persistent.
@volatile: This marks a field that can change its value outside the control of the program.
@tailrec: This annotation ensures that a method is tail-recursive.
For further knowledge about annotations in Scala, you can read the official documentation here.
View all Courses