报告可以不使用较详细或效率较低的结构,而是使用 static Integer.compare() 方法或类似方法的情况。

如果 xy 已是装箱的整数,则建议使用 x.compareTo(y)

示例:


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

在应用快速修复后:


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

Java 1.4 中引入了 Double.compare()Float.compare() 方法。 其他基元类型的方法自 Java 1.7 起即可使用了。

2017.2 的新功能