javqa中,有时候,我们需要重写类的hashCode()和toString()方法,自己去实现,太麻烦。

我们可以用apache的commons工具类来实现。

hashCode():

@override
public int hashCode(){
  return new HashCodeBuilder().append(name).toHashCode();
}

toString():

@override
public String toString(){
  return String.format("%s.name=%s",this.getClass,name);      
}

 

相关文章:

  • 2021-12-24
  • 2022-12-23
  • 2021-11-03
  • 2021-10-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-03-04
  • 2021-05-28
  • 2021-10-14
  • 2022-12-23
  • 2021-08-18
  • 2021-11-23
相关资源
相似解决方案