例如,第三方库对包使用了非常复杂的目录结构。 我可以一次导入它们吗? star 好像只能导入一级目录。
最佳答案
假设你问你是否可以做这样的事情:
import com.example.*;
// expecting packages like com.example.foo.* and com.example.bar.* to be imported
那么答案是否。您可以进行的最广泛的导入是带有星号的单个包。
JLS(第 7.5 节)defines导入语句的结构。
此外,编译器一次导入一堆包也会有问题。如果两个包提供相同的类型,都被导入,并且在类中使用了该类型,则会发生编译时错误。这在 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 - 对于 Java,我可以一次导入所有包吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5319016/