Reports cases where the static Integer.compare() method or similar methods can be used instead of more verbose or less efficient constructs.

If x and y are already boxed integers, then x.compareTo(y) is suggested.

Example:


  public int compare(int x, int y) {
    return x > y ? 1 : x < y ? -1 : 0;
  }

After the quick-fix is applied:


  public int compare(int x, int y) {
    return Integer.compare(x, y);
  }

The Double.compare() and Float.compare() methods were introduced in Java 1.4. Methods for other primitive types are available since Java 1.7.

New in 2017.2