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.
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.
The third value = Comedy
In above example, Main.third is printing particular element of the enumeration.
ID of third = 2
In above example, Main.third.id is printing default ID of any element in the enumeration.
Favourite type of Movie = Comedy
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.
Movie Genres = Movies.ValueSet(Comedy, Horror, Thriller, Romance)
- Difference between Iterator and Enumeration in Java with Examples
- Scala Tutorial – Learn Scala with Step By Step Guide
- Scala short <(x: Short): Boolean
- Scala short <(x: Char): Boolean
- Scala Extractors
- Scala | Partially Applied functions
- Scala String indexOf(String str) method with example
- Scala String contentEquals() method with example
- Scala Keywords
- Scala Int /(x: Int) method with example
- Scala Int /(x: Short) method with example
- Program to print Java Set of characters in Scala
- Scala Map size() method with example
- Scala SortedMap addString() method with a start, a separator and an end with example
- Scala Iterator addString() method with example
- Scala String substring(int beginIndex, int endIndex) method with example
- Scala | Functions Call-by-Name
- Program to convert Java list to an iterator in Scala
- Scala Set &() method with example
- Scala | Type Inference
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.