I just read a summary of some of the features that will probably be available in Java 1.5.
On of the things discussed was static imports. In this example, an import statement is defined as static. Thereafter, all references to static fields in the class can be made without referencing the class from which they came from.
import static java.awt.Color.*;
public class ImportTest {
public static void main(String args[]) {
System.out.println(RED);
}
}
My initial thought on this is that it would make your code less readable. How can you tell easily (especially when the import statement has scrolled off the page) where the constant RED comes from? What if you have two static imports. How can you easily tell which class the reference comes from. It forces you to have to do some thinking and some digging in order to find out. In my mind, saying Colors.RED is not difficult and is amazingly more clear. The name of the class actually helps disambiguate the meaning of the constant. It provides it with context.