What are annotations in Scala?

Scala categorizes annotations as meta-dataa set of data describing and giving information about other data or supplement information added to a program source code. Annotations can apply to any declaration or definition (i.e., instance variables, constructors, methods, classes, types, etc.)

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.

Built-in and Meta-annotations

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.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved