-3

I'm trying to extend LinkdList in Java through the following class definition:

public class Roster extends LinkedList<Teammate>{

}

but I get the following warning by doing so:

The serializable class Roster does not declare a static final serialVersionUID field of type long

What does that mean and how can I remove the warning?

WildBill
  • 9,143
  • 15
  • 63
  • 87

2 Answers2

4

The warning means you're not doing what you "agree" to do when you extend that class. That class trusts that you'll have a static final serialVersionUID field of type long in your class if you extend it. That's because it implements Serializable which is an interface requiring this variable.

To supress the warning add:

@SuppressWarnings("serial")

above the line where you declare the class (public class Foo)

To fix the warning declare the variable as follows:

private static final long serialVersionUID = 1812107715815332895L;

And make sure the long you use is randomly generated.

Eclipse allows both of these options as a quick-fix by clicking on the yellow lightbulb next to the line number.

Talon876
  • 1,482
  • 11
  • 17
  • Thanks. I did not see that I was implementing the Serializable Interface with this class. I'm quite the Java noob in some respects, so I'm still learning all of the ins-and-outs of the java docs. It's easy to not have the greatest bearing at first.... – WildBill Jul 05 '12 at 05:38
  • 1
    @WildBill You're welcome. Please accept my answer as the correct one if it answered your question. Thanks :) – Talon876 Jul 05 '12 at 05:39
1

The serialVersionUID is a universal version identifier for a Serializable class. Deserialization uses this number to ensure that a loaded class corresponds exactly to a serialized object. If no match is found, then an InvalidClassException is thrown.

To fix this declare a static unique id in the class -

private static final long serialVersionUID = 75264722950069776147L; // unique id

Pramod Kumar
  • 7,914
  • 5
  • 28
  • 37