VOOZH about

URL: https://www.geeksforgeeks.org/scala/enumeration-in-scala/

⇱ Enumeration in Scala - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Enumeration in Scala

Last Updated : 11 Jul, 2025

An enumerations serve the purpose of representing a group of named constants in a programming language. Refer Enumeration (or enum) in C and enum in Java for information on enumerations. Scala provides an Enumeration class which we can extend in order to create our enumerations. 
Declaration of enumerations in Scala


Output
Main Movie Genres = Movies.ValueSet(Thriller, Horror, Comedy, Romance)


Important points of enum :

  • In Scala, there is no enum keyword unlike Java or C.
  • Scala provides an Enumeration class which we can extend in order to create our enumerations.
  • Every Enumeration constant represents an object of type Enumeration.
  • Enumeration values are defined as val members of the evaluation.
  • When we extended the Enumeration class, a lot of functions get inherited. ID is one among the them.
  • We can iterate the members.


Printing particular element of the enumeration


Output
The third value = Comedy

In above example, Main.third is printing particular element of the enumeration. 

Printing default ID of any element in the enumeration


Output
ID of third = 2

In above example, Main.third.id is printing default ID of any element in the enumeration.

Matching values in enumeration


Output
Favourite type of Movie = Comedy


Changing default IDs of values
The values are printed in the order of the ID set by us.These values of IDs can be any integer .These IDs need not be in any particular order.


Output
Movie Genres = Movies.ValueSet(Comedy, Horror, Thriller, Romance)


Reference: https://www.scala-lang.org/api/current/scala/Enumeration.html

Comment

Explore