Will a method for modifying a java-computed serialVersionUid be added to 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 the modified serialVersionUID change if I add another method (and no additional fields)?

For example, adding a method:

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

Alternatively, is there a good tool to figure this out?

+3
source share
3 answers

Yes, he will change serialVersionUID.

You can use the command line tool serialver- at least in the Sun JDK, to compute serialVersionUIDfor a given compiled class.

+7
source

, . Eclipse: Serializable serialVersionUID, IDE . " UID". serialVersionUID .

+1

beans, , serialVersionUID , , . maven , .

0

Source: https://habr.com/ru/post/1710532/


All Articles