PPT Slide
Exception to the exception with String
But this special case for ‘==‘ comparison of Strings DOES NOT ALWAYS WORK . . .
Consider: If one of the Strings were created with use of the ‘new’ keyword, the two Strings would no longer share memory. (That is, ‘==‘ would be false, but equals() would still be true, if the contents of the Strings are the same.)
So, there’s an exception to the exception for Strings when you don’t use the String exception to object instantiation. Confusing? Exceptionally so!
LESSON: DON’T USE THE EXCEPTION.
Don’t compare Strings, or any Object,
with ‘==‘, even if you think the