Skip to content

Commit 3bb3c2d

Browse files
committed
More info on enum implementation
1 parent 7d326e9 commit 3bb3c2d

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

docs/docs/reference/enums.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ enum Color {
88
}
99
```
1010

11-
This defines a new class, `Color`, with three values, `Color.Red`,
11+
This defines a new `sealed` class, `Color`, with three values, `Color.Red`,
1212
`Color.Green`, `Color.Blue`. The color values are members of `Color`s
1313
companion object. The `Color` definition above is equivalent to the
1414
following more explicit definition of an _enum class_ and a companion
@@ -100,6 +100,20 @@ object Planet {
100100

101101
## Implementation
102102

103+
Enum classes are represented as `sealed` classes that extend the `scala.Enum` trait.
104+
This trait defines a single method, `enumTag`:
105+
106+
```scala
107+
package scala
108+
109+
/** A base trait of all enum classes */
110+
trait Enum {
111+
112+
/** A number uniquely identifying a case of an enum */
113+
def enumTag: Int
114+
}
115+
```
116+
103117
Enum values with `extends` clauses get expanded to anonymus class instances.
104118
For instance, the `VENUS` value above would be defined like this:
105119

0 commit comments

Comments
 (0)