Results 1 to 5 of 5
  1. #1
    RobertF is offline Member
    Join Date
    Mar 2009
    Posts
    13
    Rep Power
    0

    Default @SuppressWarnings("serial")

    Hey,
    I can't find out what the "@SuppressWarnings("serial")" actually does. I'm using eclipse and whenever I write any code the main class gets underlined and says:

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

    It says I need to add a serial version ID or suppress it. Why does it do this and is there any way I can stop it? Or is it perfectly normal? It never use to do it!

    Thanks =]

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    SupressWarnings is an annotation that informs the compiler that it should not produce the serialversionuid warning. The warning comes whenever you extend a class that is serialisable (or create a serialisable class of your own) and don't define serialVersionUID.

    If you don't define it, then, whenever the class is serialised / deserialised a serialVersionUID will be generated, and if the serialising generation does not match the deserialising generation (which will be generated from that VM's version of the Class) the deserialisation will fail, even if the Class definitions where compatable (i.e. nothing about the Class had changed enough to prevent the (de)serialisation).

  3. #3
    RobertF is offline Member
    Join Date
    Mar 2009
    Posts
    13
    Rep Power
    0

    Default

    is there anyway to make a class so its not serialisable?

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Not if you are extending one that is. (at least in relation to this warning)

    If you don't think that the class will ever be serialised, or you happy with letting the JVM generate an ID at serialisation, then go ahead and add the SuppressWarning annotation.

  5. #5
    RobertF is offline Member
    Join Date
    Mar 2009
    Posts
    13
    Rep Power
    0

    Default

    Thanks! I still don't really understand but I'll keep the Suppress Warning for now and hope everythings ok =S

Similar Threads

  1. Java, Military Format using "/" and "%" Operator!!
    By sk8rsam77 in forum New To Java
    Replies: 11
    Last Post: 02-26-2010, 03:03 AM
  2. Replies: 2
    Last Post: 01-24-2009, 06:56 PM
  3. Replies: 1
    Last Post: 10-20-2008, 07:35 AM
  4. <core:forEach var="" begin="+<%=j%>+">???
    By freddieMaize in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 09-27-2008, 01:20 AM
  5. "Jumble" or "Scramble" Program
    By Shadow22202 in forum Java Applets
    Replies: 8
    Last Post: 04-30-2008, 03:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •