FindBugs - how to solve EQ_COMPARETO_USE_OBJECT_EQUALS

前端 未结 5 1732
后悔当初
后悔当初 2021-01-11 14:50

I am clueless here...

 1: private static class ForeignKeyConstraint implements Comparable {
 2: String tableName;
 3: String fkFi         


        
5条回答
  •  有刺的猬
    2021-01-11 15:28

    Findbugs is happy with:

    public int compareTo(ForeignKeyConstraint o) {
        if (this.equals(o)) {
            return 0;
        } else if (this.tableName.equals(o.tableName)) {
            // fkFieldName must be different
            return this.fkFieldName.compareTo(o.fkFieldName);
        } else {
            // tableName must be different
            return this.tableName.compareTo(o.tableName);
        }
    }
    
    @Override
    public equals() {
      ...
    }
    
    @Override
    public int hashCode() {
      ...
    }
    

提交回复
热议问题