Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The "wildcard" imports in Java only work to the immediate level at which classes are implemented.</p> <p>That is, if you have classes <code>A</code>, <code>B</code> and <code>C</code>, with fully qualified names:</p> <ul> <li><code>com.foo.bar.A</code>;</li> <li><code>com.foo.bar.B</code>;</li> <li><code>com.foo.C</code>;</li> </ul> <p>then importing <code>com.foo.bar.*</code> will allow access to <code>A</code> and <code>B</code> without further ado; but <code>C</code> will NOT be available.</p> <p>In the same vein, importing <code>com.foo.*</code> will readily have <code>C</code> available, but not <code>A</code> and <code>B</code>.</p> <p>Now:</p> <blockquote> <p>I thought that if you included a class, like in the last two example, that you effectively imported that class and inherited all of its subclasses.</p> </blockquote> <p>It does not. Even if <code>B</code> "inherits" <code>A</code>, if you choose to use the fully qualified import <code>com.foo.bar.A</code>, it WILL NOT automatically import <code>com.foo.bar.B</code>. You'll have to import <code>B</code> separately. Which makes sense: nothing forces implementations of an interface or abstract class to be in the same package as their base interface/base class, for one; and in the same project, you may have two classes named <code>B</code>, in different packages: what should the compiler do?</p> <p>Now, according to coding style conventions, which you either make up for yourself or have to obey in your work environment, such wildcard imports may be purely and simply forbidden, and you'll have to import <code>A</code> and <code>B</code> separately. As to static imports, they have other problems...</p> <p>Finally, note that by default, you can use all of <code>java.lang.*</code> without having to declare an import.</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