What algorithm is used by eclipse to generate verison id in Serializable class?

。_饼干妹妹 提交于 2019-12-23 10:34:08

问题


Suppose here is my class :

class B implements Serializable {

    private static final long serialVersionUID = -5186261241138469827L; // what algo is used to generate this
     ..........
}

What algorithm eclipse uses to generate serialVersionUID = -5186261241138469827L ?


回答1:


Eclipse implements the relevant Java spec to compute Serialization ID.

In Eclipse, this is implemented by calculateSerialVersionId method in org.eclipse.jdt.internal.ui.text.correction.SerialVersionHashOperation class.




回答2:


Java Object Serialization Specification Docs ,given that algo

The hash value is assembled from the first and second 32-bit values of the SHA-1 message digest. If the result of the message digest, the five 32-bit words H0 H1 H2 H3 H4, is in an array of five int values named sha, the hash value would be computed as follows:

  long hash = ((sha[0] >>> 24) & 0xFF) |
              ((sha[0] >>> 16) & 0xFF) << 8 |
              ((sha[0] >>> 8) & 0xFF) << 16 |
              ((sha[0] >>> 0) & 0xFF) << 24 |
              ((sha[1] >>> 24) & 0xFF) << 32 |
              ((sha[1] >>> 16) & 0xFF) << 40 |
              ((sha[1] >>> 8) & 0xFF) << 48 |
              ((sha[1] >>> 0) & 0xFF) << 56;


来源:https://stackoverflow.com/questions/19088828/what-algorithm-is-used-by-eclipse-to-generate-verison-id-in-serializable-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!