Monday, May 25, 2009

When I first started using Java, I used wildcard imports all the time. Now, I never use them. They make grepping for the uses of a class much more difficult.

When I first learned about import static (introduced in JDK 1.5), I thought it was something that I would never use. I still think I'll never use a wildcard import static.

However, there were a bunch of classes that extended one abstract class, and I wanted to change to extend another abstract class. Those classes used a bunch of static methods in the original abstract class, so, at first, I started changing each reference to be prefixed with the original class. After a while of this stupidity, I remembered the import static feature, and that made the change a lot easier.

Another import feature that I sometimes want is an "import as" feature. Something like

import java.sql.Date : SQLDate;

or

import SQLDate = java.sql.Date;

because java.sql.Date and java.util.Date can't both be imported.

No comments:

Post a Comment