compareTo equals toString when it works

compareTo equals toString when it works

 

 Rewrite hashcode after equals rewrite

Collections.sort(localTree1.getSonList());//When using this, the entity must implement the Comparable interface and write the compareTo method (Tree), similar to list.removeAll(); the entity class needs to override equals

 public int compareTo(Object arg0)

  {

    if (arg0 == null) {

      return 1;

    }

    if (Integer.valueOf(this.type).compareTo(Integer.valueOf(((Tree)arg0).getType())) == 0) {

      return Integer.valueOf(this.displayOrder).compareTo(Integer.valueOf(((Tree)arg0).getDisplayOrder()));

    }

    return Integer.valueOf(this.type).compareTo(Integer.valueOf(((Tree)arg0).getType()));

  }

 

public boolean equals(Object arg0)

  {

    if (arg0 == null) {

      return false;

    }

    MenuFolder po = (MenuFolder) arg0;

    return this.id.equals(po.getId());

  }

  //The standard way of writing is to rewrite equals and the hashcode method must be rewritten, because equals equals hashcode must be equal (this is the norm, involving internal judgment when using some data structures), otherwise it may not be ignored

  public int hashCode()

  {

    return this.id.hashCode();

  }

 

 

When printing objects 

      System.out.println must implement toString method

public class BasAreaBeanVo implements Serializable {

private static final long serialVersionUID = 1L;

 

private String areaKey;

public String toString(){

return ToStringBuilder.reflectionToString(this);

}

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326535703&siteId=291194637