Thursday, September 2, 2010

old code: comparing string length with 0

Today, for the 100th time (I've been counting!), I encountered this snippet of code:

 String blah...;
 if (blah.length() <= 0) {
 ...


I've been wondering why blah.length() is being checked instead isEmpty(). (Why the string length is being checked for less than zero is a deeper mystery to me).

I dug into it a little, and it turns out that isEmpty was only introduced in Java 6, way back in 2006. Our code is really that old mature!

No comments:

Post a Comment