How to generate a checksum for an java object

后端 未结 10 797
生来不讨喜
生来不讨喜 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条回答
  •  抹茶落季
    2020-12-13 01:47

    Hashcode is OK. Either given class overrides equals and also, as contract demands, hashcode. By contract, if equals returns true hashcode must be the same.
    Or class doesn't override equals. In this case different executions of your application cannot produce same object, so there is no problem.
    The only problem is that some classes (even from Java API) break contract for equals.

提交回复
热议问题