Skip to content

Commit 82ec024

Browse files
committed
update desugarEnums doc
1 parent 93b9361 commit 82ec024

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

docs/docs/reference/enums/desugarEnums.md

+9-10
Original file line numberDiff line numberDiff line change
@@ -156,31 +156,30 @@ map into `case class`es or `val`s.
156156
a type parameter of the case, i.e. the parameter name is defined in `<params>`.
157157

158158

159-
### Translation of Enumerations
159+
### Translation of Enums with Singleton Cases
160160

161-
Non-generic enums `E` that define one or more singleton cases
162-
are called _enumerations_. Companion objects of enumerations define
163-
the following additional synthetic members.
161+
An enum `E` (possibly generic) that defines one or more singleton cases
162+
will define the following additional synthetic members in its companion object (where `E'` denotes `E` with
163+
any type parameters replaced by wildcards):
164164

165-
- A method `valueOf(name: String): E`. It returns the singleton case value whose
165+
- A method `valueOf(name: String): E'`. It returns the singleton case value whose
166166
`toString` representation is `name`.
167-
- A method `values` which returns an `Array[E]` of all singleton case
168-
values in `E`, in the order of their definitions.
167+
- A method `values` which returns an `Array[E']` of all singleton case
168+
values defined by `E`, in the order of their definitions.
169169

170-
Companion objects of enumerations that contain at least one simple case define in addition:
170+
If `E` contains at least one simple case, its companion object will define in addition:
171171

172172
- A private method `$new` which defines a new simple case value with given
173173
ordinal number and name. This method can be thought as being defined as
174174
follows.
175175
```scala
176-
private def $new(_$ordinal: Int, $name: String) = new E {
176+
private def $new(_$ordinal: Int, $name: String) = new E with runtime.EnumValue {
177177
def $ordinal = $_ordinal
178178
override def toString = $name
179179
$values.register(this) // register enum value so that `valueOf` and `values` can return it.
180180
}
181181
```
182182

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

186185
### Scopes for Enum Cases

0 commit comments

Comments
 (0)