Is it good practice to suppress warnings?

Sometimes when writing Java in Eclipse, I write code that generates warnings. Common is this that I get when extending a class Exception:

public class NumberDivideException extends Exception {

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

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

Warning:

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

I know that this warning is caused by my failure ... well, it says right above. I could solve this by including serialVersionUID, but this is a one-hour assignment for the school; I do not plan to serialize it anytime soon ...

Another option, of course, is the ability to add Eclipse @SuppressWarnings("serial").

But every time my mouse hangs over an option Suppress, I feel a little guilty.

, ?

( , "" serialVersionUID serialVersionUID = -1049317663306637382L; serialVersionUID - ?)


EDIT: , , ... ! , ...

+3
6

- ,

+4

, , , , , , . . Windows → → Java → → /

Java, , , Java , , . .

+6

, , , (, java doc)

, , , , .

+2

, - , , - " " - , , .

/ , - "". , , ...

+1

. . , , . , , , , - , , . , , .

0

, , , , .

This not only ensures that the warnings that you did NOT expect reached you, but it serves as an explicit note to the project - pointing to the next person who is editing the code (or on your own in a month), who you are aware of this problem, and made a deliberate decision about the acceptability of this code. This saves the next person from having to re-evaluate the situation.

(I don’t know enough about Eclipse to make this happen - this is a general principle that applies in different languages.)

0
source

Source: https://habr.com/ru/post/1741624/


All Articles