compareByIndex<T extends Enum> method Null safety

  1. @Since("2.15")
int compareByIndex<T extends Enum>(
  1. T value1,
  2. T value2
)
@Since("2.15")

Compares two enum values by their index.

A generic Comparator function for enum types which orders enum values by their index value, which corresponds to the source order of the enum element declarations in the enum declaration.

Implementation

@Since("2.15")
static int compareByIndex<T extends Enum>(T value1, T value2) =>
    value1.index - value2.index;