Back to Intellij Community

EqualsCalledOnEnumConstant

java/java-impl/resources/inspectionDescriptions/EqualsCalledOnEnumConstant.html

2025.3-rc-2440 B
Original Source

Reports equals() calls on enum constants.

Such calls can be replaced by an identity comparison (==) because two enum constants are equal only when they have the same identity.

A quick-fix is available to change the call to a comparison.

Example:

boolean foo(MyEnum value) {
    return value.equals(MyEnum.FOO);
  }

After the quick-fix is applied:

boolean foo(MyEnum value) {
    return value == MyEnum.FOO;
  }