What is serialVersionUID?

R

RC

import javax.servlet.*;
import javax.servlet.http.*;

public class MyClass extends HttpServlet {
.....
}

warning: [serial] serializable class MyClass has no definition of
^
serialVersionUID
public class MyClass extends HttpServlet {

What is this warning message mean?
How do I get rid it?

Thank Q very much in advance!

P.S. I know a warning message is NOT an error, but
someday, sometime may be cause run time failure.
 
I

Ingo R. Homann

Hi,
import javax.servlet.*;
import javax.servlet.http.*;

public class MyClass extends HttpServlet {
....
}

warning: [serial] serializable class MyClass has no definition of
^
serialVersionUID
public class MyClass extends HttpServlet {

What is this warning message mean?

You need a serialVersionId, if your class implements "Serializable".
HttpServlet does so, and so you need such an id. (It is used, if the
Servlet-Context is relaunched and your sessions should be made
persistant / restored. If you do not need this feature, you do not need
a serialVersionId.)
How do I get rid it?

There is some switch to disable the warning (e.g. in Eclipse...)
P.S. I know a warning message is NOT an error, but
someday, sometime may be cause run time failure.

Yes, its better not to ignore warnings (although that's not possible
with Java5 :-()

Ciao,
ingo
 
B

blaine

You'll need to add a serialVersionUID to your class eg:

public class MyClass extends HttpServlet{
public static final long serialVersionUID = 1L;

public MyClass(){
}
}
 
S

Skip

You'll need to add a serialVersionUID to your class eg:

public class MyClass extends HttpServlet{
public static final long serialVersionUID = 1L;

public MyClass(){
}
}

That static field may be private too.
 
B

Bryce

Hi,
import javax.servlet.*;
import javax.servlet.http.*;

public class MyClass extends HttpServlet {
....
}

warning: [serial] serializable class MyClass has no definition of
^
serialVersionUID
public class MyClass extends HttpServlet {

What is this warning message mean?

You need a serialVersionId, if your class implements "Serializable".
HttpServlet does so, and so you need such an id. (It is used, if the
Servlet-Context is relaunched and your sessions should be made
persistant / restored. If you do not need this feature, you do not need
a serialVersionId.)
How do I get rid it?

There is some switch to disable the warning (e.g. in Eclipse...)
P.S. I know a warning message is NOT an error, but
someday, sometime may be cause run time failure.

Yes, its better not to ignore warnings (although that's not possible
with Java5 :-()

Added note:

If you are using Eclipse, it can generate the id for you. Click on the
yellow lightbulb.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,173
Latest member
GeraldReund
Top