Should a null value for an expected collection be preferred or an empty Collection object? Lets see through a program:
Running this on my laptop with Java 6 produced:
import java.util.Collection;
import java.util.Vector;
import static java.lang.System.out;
public class E {
public void isNull (Collection col) {
long t = System.nanoTime();
if (col == null) {
}
out.println ("Time to check null: " + (System.nanoTime () - t));
}
public void isEmpty (Collection col) {
long t = System.nanoTime ();
if (col.isEmpty ()) {
}
out.println ("Time to check empty: " + (System.nanoTime () - t));
}
public static void main (String args []) {
E e = new E ();
e.isNull ((Collection) null);
e.isEmpty (new Vector ());
}
}
Time to check null: 45234Something to think about..
Time to check empty: 10750
No comments:
Post a Comment