Skip to content

Commit

Permalink
Fix some mistakes in the EnumOrdinal examples
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 610431336
  • Loading branch information
Stephan202 authored and Error Prone Team committed Feb 26, 2024
1 parent f3dbb09 commit 297019c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions docs/bugpattern/EnumOrdinal.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ Prefer using enum value directly:
ImmutableMap<MyEnum, String> MAPPING =
ImmutableMap.<MyEnum, String>builder()
.put(MyEnum.FOO, "Foo")
.put(MyEnum.BAR, "Bar");
.put(MyEnum.BAR, "Bar")
.buildOrThrow();
```

to this:

```java
ImmutableMap<Integer, String> MAPPING =
ImmutableMap.<MyEnum, String>builder()
ImmutableMap<Integer, String> MAPPING =
ImmutableMap.<Integer, String>builder()
.put(MyEnum.FOO.ordinal(), "Foo")
.put(MyEnum.BAR.ordinal(), "Bar");
.put(MyEnum.BAR.ordinal(), "Bar")
.buildOrThrow();
```

Or if you need a stable number for serialisation, consider defining an explicit
Expand Down

0 comments on commit 297019c

Please sign in to comment.