Don’t import wildcards from non-standard Java packages

Import statements provide good documentation, but not if they contain wildcards. For example:

import com.zikzak.db.*;
import com.zikzak.util.*;

   ...code...

WidgetId = new WidgetId();

There’s no way to find out what package the WidgetId class belongs to without searching through the source tree. Much better to do this instead:

import com.zikzak.db.Table;
import com.zikzak.util.WidgetId;

   ...code...

WidgetId = new WidgetId();

Now it’s clear what and where WidgetId is.

This is not such a problem with well-known packages. For example, everybody knows what classes are in the java.util package, so this probably won’t cause any confusion:

import java.util.*;
Share This | Comments | Permalink | Trackback | Comments feed

Post a comment

(required)
(required)
Close
E-mail It