Name Conflicts when importing packages

It is possible that you will try to import a package that contains classes that have the same name as a class in your own source code. In general you should try to avoid this, especially when the conflict is with a class in the java packages.

The two classes may or may not mean the same thing. In general you should probably rename the class in your own source code rather than in the package. However if the two classes with conflicting names are related functionally, it may make sense to implement your class as a subclass of the class in the package.

There are a couple of name conflicts in the class library. The worst offenders are java.util.List and java.awt.List. The second worst offenders are java.sql.Date and java.util.Date, though this case is somewhat mitigated because java.sql.Date is a subclass of java.util.Date. If you need to use one or both of the conflictingly named classes as well as importing the other package, you simply have to use the full package qualified name, inconvenient as it may be to type.

Previous | Next | Top | Cafe au Lait

Copyright 1997-1999 Elliotte Rusty Harold
Last Modified September 7, 1999