Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a good practice to suppress warnings?

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?)


EDIT: Upon seeing answers, it appears my question may be slightly argumentative... Sorry! Too late for me to delete though...

like image 777
Chris Cooper Avatar asked Dec 03 '25 10:12

Chris Cooper


1 Answers

It's very satisfying to have code compile with out warnings - and when you do get one it then stands out and may alert you to a problem in the code

like image 117
hamishmcn Avatar answered Dec 06 '25 09:12

hamishmcn