by prokoba · 17y ago · 0 comments
In Java/C# this can throw a null pointer exception:
myString.equals("another string");
however this will never throw anything:
"another string".equals(myString); //false if myString is null, this is what you mean in most cases anyway
I use that like crazy. I'm not sure if Java has something similar now. Years ago when I used java, I remember being constantly frustrated with having to write a helper method in every project to do { return myString==null || myString.equals("");}
I did find "something".equals(myString) helpful though.