问题
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