So the Serializable interface is empty, but you get a warning if you dont add the serialVersionUID variable into the class. Is it possible to create an interface that does this same thing?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
So the Serializable interface is empty, but you get a warning if you dont add the serialVersionUID variable into the class. Is it possible to create an interface that does this same thing?
I think that there's some behind the scenes magic with Serializable that mere mortals cannot create by simply creating a marker interface.
if you wanna create an interface, that marks a class with exactly this warning, then just let your own interface extends the Serialzable.
public interface MySerializable extends Serializable
for your own warnings I am afraid that you must write your own validator(if you use eclipse for example)
BTW the Serializable is a marker interface. It is use by the output and especially the input streams with reflection to find out which fields in an inheritance hierarchy are initialized from disc and which via optional constructors.
the serialVersionUID there is to find out the version of a class if you deserialize an older class version object, I think