Skip to content

Commit db9029c

Browse files
committed
update desugar docs
1 parent 004ddb3 commit db9029c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

docs/docs/reference/enums/desugarEnums.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,15 @@ Companion objects of enumerations that contain at least one simple case define i
174174
follows.
175175
```scala
176176
private def $new(_$ordinal: Int, $name: String) = new E {
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

183183
The anonymous class also implements the abstract `Product` methods that it inherits from `Enum`.
184-
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.
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`.
185186

186187
### Scopes for Enum Cases
187188

0 commit comments

Comments
 (0)