incava.org

null considered harmful

Quick ... what is the last parameter in the following code?

dlg.create(width, height, "File not readable", null, null);

How about this one?

dlg.create(width, height, "File not readable", Icon.NONE, SoundClip.NONE);

There is an alternative to the heavy usage of null in Java code: for each class, define a public static variable NONE, with the variable type being that class, and initialize it to null. For example:

public class SoundClip
{
    public final static SoundClip NONE = null;

    // ... rest of class
}

And use SoundClip.NONE instead of null as a parameter, as in the previous example.

This takes better use of type safety/checking in Java, and makes code much easier to read.

Valid HTML 4.01!

Valid CSS!