对于Java,我可以一次导入所有包吗? [英] For Java, can I import all packages at once?
问题描述
例如,第三方库对包使用非常复杂的目录结构。
我可以一次导入它们吗?明星似乎只能导入一个目录级别。
For example, the third party library uses very complex directory structure for the package. Can I import them at once. the star seems can only imports one directory level.
推荐答案
假设您在询问是否可以执行以下操作:
Assuming you're asking whether or not you can do something like:
import com.example.*;
// expecting packages like com.example.foo.* and com.example.bar.* to be imported
然后答案是否。你可以做的最广泛的导入就是一个带星星的包。
Then the answer is no. The widest import you can make is a single package with a star.
JLS(7.5节)定义导入语句的结构。
The JLS (section 7.5) defines the structure for import statements.
此外,它将是编译器一次导入一堆包有问题。如果两个包提供相同的类型,两者都被导入,并且类在类中使用,则会发生编译时错误。这在 JLS 6.5.5.1 中有所描述:
Additionally, it would be problematic for the compiler to import a bunch of packages at once. If two packages provide the same type, both are imported, and the type is used in the class, a compile-time error occurs. This is described in JLS 6.5.5.1:
否则,如果该名称的类型是
,则由多于一个
类型 - 按需导入声明声明
编译单元,然后名称是
不明确的类型名称;发生
编译时错误。
Otherwise, if a type of that name is declared by more than one type-import-on-demand declaration of the compilation unit, then the name is ambiguous as a type name; a compile-time error occurs.
这篇关于对于Java,我可以一次导入所有包吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!