Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will adding a method change the java-calculated serialVersionUid on my class?

If I have a class like this:

public class Name implements Serializable {
    private final String firstName;
    private final String lastName;

    public Name(String firstName, String lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
    }

    public String getFirstName() {
        return firstName;
    }

    public String getLastName() {
        return lastName;
    }
}

Will its calculated serialVersionUID change if I add another method (and no additional fields)?

For example, adding the method:

public String getFullName() {
    return firstName + " " + lastName;
}

Alternatively, is there a nice tool for figuring this out?

like image 681
Pete Doyle Avatar asked Jan 24 '23 12:01

Pete Doyle


1 Answers

Yes, it will change the serialVersionUID.

You can use the serialver command line tool - at least in Sun's JDK to calculate the serialVersionUID for a given compiled class.

like image 62
Robert Munteanu Avatar answered May 16 '23 07:05

Robert Munteanu