I took the source for the HelloWorld example in the Tomcat5 samples (http://your.server:8080/servlets-examples/helloworld.html), and tried to compile it.
[javac] Compiling 1 source file to /home/ccurley/src/com/charlescurley/hello/classes [javac] ---------- [javac] 1. WARNING in /home/ccurley/src/com/charlescurley/hello/src/HelloWorld.java [javac] (at line 5) [javac] public class HelloWorld extends HttpServlet { [javac] ^^^^^^^^^^ [javac] The serializable class HelloWorld does not declare a static final serialVersionUID field of type long [javac] ---------- [javac] 1 problem (1 warning)
What am I missing here?
[ccurley@taltos src]$ echo $CLASSPATH /usr/share/tomcat5/bin/:/usr/bin:/usr/share/java/servletapi5.jar:.
* Charles Curley charlescurley@charlescurley.com [2005-08-23 22:20]:
[javac] ---------- [javac] 1. WARNING in /home/ccurley/src/com/charlescurley/hello/src/HelloWorld.java
[...] [javac] The serializable class HelloWorld does not declare a static final serialVersionUID field of type long [javac] ---------- [javac] 1 problem (1 warning)
What am I missing here?
Isn't that just a warning and not an error? ecj is a little more particular than other bytecode compilers WRT serialVersionUIDs IIRC.
Andrew
On Tue, Aug 23, 2005 at 11:16:21PM -0400, Andrew Overholt wrote:
- Charles Curley charlescurley@charlescurley.com [2005-08-23 22:20]:
[javac] ---------- [javac] 1. WARNING in /home/ccurley/src/com/charlescurley/hello/src/HelloWorld.java
[...] [javac] The serializable class HelloWorld does not declare a static final serialVersionUID field of type long [javac] ---------- [javac] 1 problem (1 warning)
What am I missing here?
Isn't that just a warning and not an error? ecj is a little more particular than other bytecode compilers WRT serialVersionUIDs IIRC.
Andrew
I guess I'm a little picky about warnings. I learned way back when ANSI C was all the latest rage that ignoring them was not a good idea.
Anyway, turns out the solution is to declare the dang thing:
public class HelloWorld extends HttpServlet { static final long serialVersionUID = 0;
Now a C compiler (or lint) would have complained that it isn't used. Sigh.
Thanks
"Charles" == Charles Curley charlescurley@charlescurley.com writes:
Charles> public class HelloWorld extends HttpServlet { Charles> static final long serialVersionUID = 0;
Charles> Now a C compiler (or lint) would have complained that it isn't Charles> used. Sigh.
java compilers should know to special case serialVersionUID. It is customary to make this private.
Tom
java-devel@lists.fedoraproject.org