Answer the question
In order to leave comments, you need to log in
Why is using .equals(null) bad?
Recently completed my first java project. I was looking for a code review and found out about the existence of static code analyzers, like findbugs. Installed SpotBugs Eclipse Plugin and instructed to check my project. He found a bug that I don't understand.
Based on the JButton, I made a round button and wrote a color assignment function for it (class variable color_normal), which also assigns a "reverse" color (color_pressed) to the pressed state.
public void setColor(Color c) {
color_normal = c.equals(null) ? Color.WHITE : c;
color_pressed = c.equals(null) ? Color.GRAY : new Color(255 - color_normal.getRed(), 255 - color_normal.getGreen(), 255 - color_normal.getBlue());
}
Answer the question
In order to leave comments, you need to log in
Well, it's written there, have you even read it? Let me quote:
This method calls equals(Object), passing a null value as the argument. According to the contract of the equals() method, this call should always return false.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question