4 ms·
I've seen this in an old book (Code Complete?) a few aeons ago, and I can't say I like it, but I use it a lot. In Java/C# this can throw a null pointer excepti
by prokoba 17y ago
I've seen this in an old book (Code Complete?) a few aeons ago, and I can't say I like it, but I use it a lot.
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
- danek 17y agoin c# you wouldn't use the .Equals() method. You just do myString == someOtherString. Also it has a nice static method on the string class: if( string.IsNullOrEmpty(mystring) ){} 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.