Skip to content

Commit 21aee87

Browse files
authored
Merge pull request #10441 from fgoret/patch-2
Added fromOrdinal method to enums doc
2 parents 9f83b52 + 499e716 commit 21aee87

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

docs/docs/reference/enums/enums.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,19 @@ scala> red.ordinal
4242
val res0: Int = 0
4343
```
4444

45-
The companion object of an enum also defines two utility methods.
45+
The companion object of an enum also defines three utility methods.
4646
The `valueOf` method obtains an enum value
4747
by its name. The `values` method returns all enum values
48-
defined in an enumeration in an `Array`.
48+
defined in an enumeration in an `Array`. The `fromOrdinal`
49+
method obtains an enum value from its ordinal (Int) value.
4950

5051
```scala
5152
scala> Color.valueOf("Blue")
5253
val res0: Color = Blue
5354
scala> Color.values
5455
val res1: Array[Color] = Array(Red, Green, Blue)
56+
scala> Color.fromOrdinal(0)
57+
val res2: Color = Red
5558
```
5659

5760
### User-defined members of enums

0 commit comments

Comments
 (0)