Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

warning: [serial] serializable class SomeClass has no definition of serialVersionUID

Tags:

java

netbeans

Eventhough this class is not intended ot set to be serializable, I'm getting this unusual warning! Could someone let me know if you have come across such odd warning?!

C:\Documents and Settings\...filename.java:60: warning: [serial] serializable class SomeClass has no definition of serialVersionUID
public class NewPortalConnection extends javax.swing.JFrame {

Regards

like image 575
Sam Avatar asked Oct 19 '11 15:10

Sam


3 Answers

This warning comes when you derive from a class that implements Serializable. In your case, the Serializable parent class is JFrame.

You can suppress this warning with @SuppressWarnings("serial"), or give the class a serialVersionUID: private static final long serialVersionUID = ...; (with a long value for the dots).

There is a discussion here on SO on which is preferable.

like image 95
S.L. Barth Avatar answered Oct 22 '22 18:10

S.L. Barth


JFrame implements Serializable, so all extending classes also implement Serializable.

Here's a tutorial about Serializable and serialVersionUID, but to really understand the topic you should read Chapter 11 of Effective Java (2nd Ed) by Joshua Bloch

like image 41
Sean Patrick Floyd Avatar answered Oct 22 '22 17:10

Sean Patrick Floyd


If you know your application never serializes things, add -Xlint:-serial to command line arguments of javac. For example,

javac -Xlint -Xlint:-serial *****

This way you will have all warnings except "serial".

like image 34
VasiliNovikov Avatar answered Oct 22 '22 18:10

VasiliNovikov