Java import operation with * not class collection

(Disclaimer: I'm new to Java, and also, I read the relevant SO question .)

I have the following code:

import org.apache.pdfbox.pdmodel.*; ... PDFont font = PDType1Font.HELVETICA_BOLD; 

But the PDFont class PDFont not recognized in Eclipse.

When I add the following:

 import org.apache.pdfbox.pdmodel.font.PDFont; 

The class PDFont .

Given that the PDFont class is under the hierarchy specified in the first import statement, ending with an asterisk, why do we need a specific import operation?

Also, is there a way to find the location of a class in a library if you don't have documentation convenient?

+5
source share
1 answer

Ads for import are not recursive

The declaration of type-import-on-demand allows all available types to have a named package or a type that must be imported as needed.

PDFont type is in package

 org.apache.pdfbox.pdmodel.font 

but you tried to import

  import org.apache.pdfbox.pdmodel.*; 

The org.apache.pdfbox.pdmodel package does not contain a type named PDFont .

So you could use

  import org.apache.pdfbox.pdmodel.font.*; 

Also, is there a way to find the location of a class in a library if you don't have documentation?

If the library is published as .jar , you can unzip it and search it.

Most IDEs usually have a function to search for types by their simple name. For example, in Eclipse you can use CTRL (cmd) + SHIFT + T and enter a simple or full name for the search (if it is in the classpath).

+12
source

Source: https://habr.com/ru/post/1209929/


All Articles