Java : “xx”.equals(variable) better than variable.equals(“xx”) , TRUE?
I'm reviewing a manual of best practices and recommendation coding java I think is doubtful. Recomendation: String variable; "xx".equals(variable) // OK variable.equals("xx") //Not recomended Because prevents appearance of NullPointerException that are not controlled Is this true? Mark Byers This is a very common technique that causes the test to return false if the variable is null instead of throwing a NullPointerException . But I guess I'll be different and say that I wouldn't regard this as a recommendation that you always should follow. I definitely think it is something that all Java