See the following code:
enum ChunkIndex {
ZeroIndex = 0,
SpecializedIndex = ZeroIndex,
SmallIndex = SpecializedIndex + 1,
MediumIndex = SmallIndex + 1,
HumongousIndex = MediumIndex + 1,
NumberOfFreeLists = 3,
NumberOfInUseLists = 4
};
ChunkIndex index0 = (ChunkIndex) (0);
ChunkIndex index3 = (ChunkIndex) (3);
ChunkIndex index4 = (ChunkIndex) (4);
You see that there exists at least two enum values that equal to 0.
The same as 3.
What will happen when cast 0 to enum ChunkIndex?
The same question with 3.
The code above is from jdk8/openjdk/hotspot/src/share/vm/memory/metaspace.cpp line 83 and its above 7 lines.