(Disclaimer: I am new to Java and also, I have read the related SO question.)
I have the following code:
import org.apache.pdfbox.pdmodel.*;
...
PDFont font = PDType1Font.HELVETICA_BOLD;
But the PDFont
class is not recognized in Eclipse.
When I add the following:
import org.apache.pdfbox.pdmodel.font.PDFont;
The PDFont
class is picked up.
Given that the PDFont
class is located under the hierarchy specified in the first import statement ending with the asterisk, why is a specific import statement necessary?
Also, is there a way to search for the location of a class in a library if one doesn't have the documentation handy?
The on demand import
declarations are not recursive
A type-import-on-demand declaration allows all accessible types of a named package or type to be imported as needed.
Your PDFont
type is in package
org.apache.pdfbox.pdmodel.font
but you've tried to import
import org.apache.pdfbox.pdmodel.*;
the package org.apache.pdfbox.pdmodel
does not contain a type named PDFont
.
So, alternatively, you could have used
import org.apache.pdfbox.pdmodel.font.*;
Also, is there a way to search for the location of a class in a library if one doesn't have the documentation handy?
If the library is published as a .jar
, you can unzip it and search through it.
Most IDEs typically have a feature to search types by their simple name. For example, in Eclipse, you can use CTRL (cmd) + SHIFT + T
and type the simple or fully qualified name to search for (if it's on the classpath).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With