Next: Naming Convention
Up: Source Files
Previous: Organization of source file
Use explicit import statements i.e. use
import java.util.Map;
import java.util.Set;
and not
import java.util.*;
And, ordered them in alphabetic order so that we easily locate them.
We discourage wildcard type-import-on-demand declarations for several reasons:
- Someone can later add a new unexpected class file to the same package that you are importing. This new class can conflict with a type you are using from another package, thereby turning a previously correct program into an incorrect one.
- Explicit class imports clearly convey to a reader the exact classes that are being used (and which classes are not being used).
- Explicit class imports provide better compile performance. While type-import-on-demand declarations are convenient for the programmer and save a little bit of time initially, this time is paid for in increased compile time every time the file is compiled.
The -verboseflag in the javac compiler can be used to discover which types are actually being imported, in order to convert type-import-on-demand declarations to fully qualified ones.
Next: Naming Convention
Up: Source Files
Previous: Organization of source file
Dennis Seah
Mon Jul 17 11:43:42 2006