![]() ![]() If you have any doubts about Enum being Serializable, run the HotSpot-provided serialver tool against your favorite enum that does not declare itself Serializable. Once this is removed, the import statement for the java.io.Serializable interface can also be removed. ![]() This.stateAbbreviation = newStateAbbreviation īecause enums are automatically Serializable (see Javadoc API documentation for Enum), there is no need to explicitly add the "implements Serializable" clause following the enum declaration. StateEnum(final String newStateName, final String newStateAbbreviation) Private static final long serialVersionUID = 42L an arbitrary constant such as 42L for all versions use serialver on Sun JDK Don't do this: Don't specify serialVersionUID for enums and don't use Public enum StateEnum implements Serializable * Constants") of the "Java Object Serialization Specification Version 6.0". The Enum is already Serializable and attempts to control its * Enum example with unnecessary and ignored serialization specification More than once, I have seen code such as the following (without the comments I have added to point out flaws), in which a well-intentioned Java developer has ensured that their favorite Enum explicitly declares that it is Serializable and has even provided a serialVersionUID for it. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |