I have imported packages using *.
*
Example:
import java.awt.*;
Is there any way to find out which classes of this package I actually use in my program? I need to import only the classes that I actually use for my Java project.
thank
It’s good practice not to use * for import unless you use each of them. This will cause the executable to be unnecessarily large.
As the @Bill Lizard said, the compiler will tell you which imports you forgot to add.
IDE, Eclipse, , , .
Eclipse Ctrl + Shift + O ( ).
IntelliJ, Ctrl + Alt + O.
*, , , - , Oracle jdeps, JDK. :
jdeps
jdeps Java. .class, , JAR ...
.class
, classes, , com.example.Foo:
classes
com.example.Foo
jdeps -verbose:class -cp classes com.example.Foo
. jdeps .
(getPackage() getClassName()) .
{
System.out.println(Class.class.forName("java.lang.Integer").getPackage()); } catch(ClassNotFoundException ex) { System.out.println(ex.toString()); }