serialVersionUID can be generated by using getSerialVersionUID()
method of the ObjectStreamClass class.
SerialiazedClass.java
package com.serial;
import
java.io.Serializable;
class SerialiazedClass
implements Serializable {
String name;
public void
setName(String name) {
this.name = name;
}
}
GenerateSerialVerUID.java
import java.io.ObjectStreamClass;
public class GenerateSerialVerUID {
public static void main(String[] args) {
Class hashClass = SerialiazedClass.class;
ObjectStreamClass
osc =
ObjectStreamClass.lookup(hashClass);
long serialID = osc.getSerialVersionUID();
System.out.println(serialID);
}
}
Output:
1623809446810541828
No comments:
Post a Comment