Skip to content

Commit 9dd1e00

Browse files
committed
update desugar docs
1 parent 0360b47 commit 9dd1e00

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

docs/docs/reference/enums/desugarEnums.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,15 @@ If `E` contains at least one simple case, its companion object will define in ad
174174
follows.
175175
```scala
176176
private def $new(_$ordinal: Int, $name: String) = new E with runtime.EnumValue {
177-
def $ordinal = $_ordinal
178-
override def toString = $name
177+
def ordinal = _$ordinal // if `E` does not have `java.lang.Enum` as a parent
178+
override def toString = $name // if `E` does not have `java.lang.Enum` as a parent
179179
$values.register(this) // register enum value so that `valueOf` and `values` can return it.
180180
}
181181
```
182182

183-
The `$ordinal` method above is used to generate the `ordinal` method if the enum does not extend a `java.lang.Enum` (as Scala enums do not extend `java.lang.Enum`s unless explicitly specified). In case it does, there is no need to generate `ordinal` as `java.lang.Enum` defines it.
183+
The anonymous class also implements the abstract `Product` methods that it inherits from `Enum`.
184+
The `ordinal` method is only generated if the enum does not extend from `java.lang.Enum` (as Scala enums do not extend `java.lang.Enum`s unless explicitly specified). In case it does, there is no need to generate `ordinal` as `java.lang.Enum` defines it. Similarly there is no need to override `toString` as that is defined in terms of `name` in
185+
`java.lang.Enum`.
184186

185187
### Scopes for Enum Cases
186188

0 commit comments

Comments
 (0)