Is it a good practice to suppress warnings?

Posted by Chris Cooper on Stack Overflow See other posts from Stack Overflow or by Chris Cooper
Published on 2010-04-18T00:51:16Z Indexed on 2010/04/18 0:53 UTC
Read the original article Hit count: 494

Sometimes while writing Java in Eclipse, I write code that generates warnings. A common one is this, which I get when extending the Exception class:

public class NumberDivideException extends Exception {

    public NumberDivideException() {
        super("Illegal complex number operation!");
    }

    public NumberDivideException(String s) {
        super(s);
    }
} // end NumberDivideException

The warning:

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

I know this warning is caused by my failure to... well, it says right above. I could solve it by including the serialVersionUID, but this is a one hour tiny assignment for school; I don't plan on serializing it anytime soon...

The other option, of course, is to let Eclipse add @SuppressWarnings("serial").

But every time my mouse hovers over the Suppress option, I feel a little guilty.

For programming in general, is it a good habit to suppress warnings?

(Also, as a side question, is adding a "generated" serialVersionUID like serialVersionUID = -1049317663306637382L; the proper way to add a serialVersionUID, or do I have to determine the number some other way?)

© Stack Overflow or respective owner

Related posts about warnings

Related posts about best-practices