How to generate a checksum for an java object

后端 未结 10 828
生来不讨喜
生来不讨喜 2020-12-13 01:04

I\'m looking for a solution to generate a checksum for any type of Java object, which remains the same for every execution of an application that produces the same object.

10条回答
  •  旧时难觅i
    2020-12-13 01:30

    If you're f you're using Eclipse IDE then it has actions (under Source menu) to generate hashcode and equals functions. It allows you to choose the attributes of the class you want in the hashcode. This is similar to using the HashCodeBuilder approach that has already been suggested.

    Alternatively you could stream the object to a byte array and generate an MD5 of that.

提交回复
热议问题