Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The only harm that wildcard package imports can cause is an increased chance of namespace collisions if there are multiple classes of the same name in multiple packages.</p> <p>Say for example, I want to program to use the <code>ArrayList</code> class of the Java Collections Framework in an AWT application that uses a <code>List</code> GUI component to display information. For the sake of an example, let's suppose we have the following:</p> <pre><code>// 'ArrayList' from java.util ArrayList&lt;String&gt; strings = new ArrayList&lt;String&gt;(); // ... // 'List' from java.awt List listComponent = new List() </code></pre> <p>Now, in order to use the above, there would have to be an import for those two classes, minimally:</p> <pre><code>import java.awt.List; import java.util.ArrayList; </code></pre> <p>Now, if we were to use a wildcard in the package <code>import</code>, we'd have the following.</p> <pre><code>import java.awt.*; import java.util.*; </code></pre> <p>However, now we will have a problem!</p> <p>There is a <code>java.awt.List</code> class and a <code>java.util.List</code>, so referring to the <code>List</code> class would be ambiguous. One would have to refer to the <code>List</code> with a fully-qualified class name if we want to remove the ambiguity:</p> <pre><code>import java.awt.*; import java.util.*; ArrayList&lt;String&gt; strings = new ArrayList&lt;String&gt;(); // ... // 'List' from java.awt -- need to use a fully-qualified class name. java.awt.List listComponent = new java.awt.List() </code></pre> <p>Therefore, there are cases where using a wildcard package <code>import</code> can lead to problems.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload