This is incorrect.Originally posted by Adam S-R:
String s2 = null;
may actually create the string literal "", which would technically be an object and equals() could be used.
Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
The reason why s1.equals(s2) when s2 is null is the following:
the equals method in the class String will accept an Object parameter. You pass on null and this is ok.
Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
So u r saying that null can be used in place of an Object in equals()? How so, if AFAIK null isn't an Object? I am confused. Please clarify
Consider Paul's rocket mass heater. |