compareByName<T extends Enum> method Null safety

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

Compares enum values by name.

The EnumName.name of an enum value is a string representing the source name used to declare that enum value.

This Comparator compares two enum values by comparing their names, and can be used to sort enum values by their names. The comparison uses String.compareTo, and is therefore case sensitive.

Implementation

@Since("2.15")
static int compareByName<T extends Enum>(T value1, T value2) =>
    value1.name.compareTo(value2.name);