Skip to main content
gamedev.net
🔒 Locked

[java] using the java collections

Started by GonzoDick Nov 1, 2005 at 4:03 AM 2 replies 650+ views
Original Post
GonzoDick
GonzoDick
I have some questions about implementing a java core collections class(in this case TreeSet)... import java.util.*; class SortA extends TreeSet { public SortA() { super(); } public SortA(int y) { super(y); } } When I compile this(it is not the complete program btw) i get a warning: serializable class SortA has no definition of serialVersionUID So my questions are these: Why am I getting this warning? is there a way to get around this? is it possible to extend the core classes?
Son of Cain
Son of Cain
You have to add a static field in your class:

private static final long serialVersionUID = 1L;


Though I don't know if there's a pattern for this value.

Son Of Cain
a.k.a javabeats at yahoo.ca
GonzoDick
GonzoDick
I tried inserting the text into the SortA class but to avail... still got hte same warning. Also if it makes a difference i'm compiling on unix
haegarr
haegarr
You must add a line like this into SortA:
static final long serialVersionUID = 1234567890L;

Somewhere in your develepment suite there is a helper that computes a hash value from a class definition.. E.g. the stand-alone prog "serialver" does this. However, you _may_ also choose a number by your own...

Java collections classes are serializable, and all derivated classes are since serializability is yielded by inheriting java.io.Serializable or java.io.Externalizable. To distinguish classes not only by type but also by version, the serialVersionUID is used internally by Java during de-serializing. Even if you derive SortA to build a SortB then also SortB has to have its own serialVersionUID (don't bother that all these fields are named identical, it works).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.