How to generate a checksum for an java object

后端 未结 10 827
生来不讨喜
生来不讨喜 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:37

    1. Object -> String (For example, GSON - you will not have to write serialization not to list all fields of your class)

    2. String.hashCode() -> int (Instead of Object.hashCode()! This realization of hashCode() depends on content of String, not on address in memory --- you can use it across different app launches, different threads, etc.)

    (or 2. String -> md5)

提交回复
热议问题