报告 equals() 被调用以将 String 与空字符串进行比较的情况。 在这种情况下,使用 .isEmpty() 更好,因为它可以准确显示您正在检查的内容。

示例:


  void checkString(String s){
    if ("".equals(s)) throw new IllegalArgumentException();
  }

在应用快速修复后:


  void checkString(String s){
    if (s != null && s.isEmpty()) throw new IllegalArgumentException();
  }

"".equals(str)str 为空时返回 false。 为了安全起见,当 equals() 参数可以为空时,此检查的快速修复会插入一个显式的 null 检查。 使用该选项使检查忽略此类情况。