I saw this piece of code today and wanted to know is there a difference between
return (null==employeeName ? "": employeeName);
and
return (employeeName == null ? "": employeeName);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Not anymore.
It used to be the case, in the wild days of C and C++ that non-boolean expressions, were OK in if statements, so that there would be no difference, unless you made a classic programmer mistake and forgot an equals sign:
would compile, but
would not.
This doesn’t matter in Java, because an Employee type isn’t a boolean, and the compiler, rather than the syntax, stops you from shooting yourself in the foot; but whoever wrote that was probably in the habit from their days of writing C.