Because if myString
is null you get an exception. You know "aString"
will never be null, so you can avoid that problem.
Often you'll see libraries that use nullSafeEquals(myString,"aString");
everywhere to avoid exactly that (since most times you compare objects, they aren't generated by the compiler!)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…