I believe that I use the type Xin my java compilation module from the package foo.barand is Xnot defined in the compilation part itself and is not imported directly. How now does the java compiler resolve Xefficiently? There are several possibilities that Xmay include:
X can be imported through import stars a.b.*X may be in the same package as the compilation unitX can be a type of language, that is, be in java.lang
The problem I see is especially (2.). Since it Xcan be a private type of package, it is not even required to Xbe in a compilation unit with a name X.java. Thus, the compiler must examine all the class path entries and look for any classes in the package foo.bar, then it must read every class in the package foo.barto check if it is included X.
It sounds very expensive. Especially when I compile only one file, the compiler should read dozens of class files just for type search X. If I use many star names, this procedure needs to be repeated for many types (although class files will not be read twice, of course).
So is it also advisable to import types from one package to speed up the compilation process? Or is there a faster method for resolving an unimported type Xthat I could not find?
source
share