java - 对于 Java,我可以一次导入所有包吗?

标签 java

例如,第三方库对包使用了非常复杂的目录结构。 我可以一次导入它们吗? 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/

相关文章:

java - 找不到主类 :bootRepackage

java - 在Java中使用for循环时如何实现return语句?

java - 在 Hibernate 中是否不推荐使用 buildSessionFactory() 配置方法?

java - 处理映射总是越界

java - Spring SecurityContext 在错误页面上返回空认证

java - Android 上的 onActivityResult

Java方法等于循环列表

java - Ping 一个 MySQL 服务器

Java Swing 无法向面板添加多个面板

java - 当客户端关闭连接时,Spring StreamingResponseBody 请求线程未清理