The only harm that can cause import of wildcard packages is the increased likelihood of namespace conflicts if multiple packages have multiple classes with the same name.
Say, for example, I want to program the use of the ArrayList Framework Java Collections Framework class in an AWT application that uses the List GUI component to display information. For example, suppose we have the following:
// 'ArrayList' from java.util ArrayList<String> strings = new ArrayList<String>(); // ... // 'List' from java.awt List listComponent = new List()
Now, to use the above, there must be an import for these two classes, minimally:
import java.awt.List; import java.util.ArrayList;
Now, if we used a wildcard in the import package, we would have the following.
import java.awt.*; import java.util.*;
However, now we will have a problem!
There is a class java.awt.List and java.util.List , so the appeal to the List class will be ambiguous. We would have to turn to List with the full class name if we want to eliminate the ambiguity:
import java.awt.*; import java.util.*; ArrayList<String> strings = new ArrayList<String>();
Therefore, there are times when using the import wildcard package can lead to problems.
coobird Dec 31 '09 at 1:39 2009-12-31 01:39
source share