一个典型的module-info.java内容如下
Q:
在module-info.java当中,什么时候用 requires com.google.common.truth; 什么时候用requires truth; 什么时候用 requires static com.google.common.truth;
A:
在 `module-info.java` 文件中使用 `requires` 关键字时,需要根据你的项目依赖和模块化需求来选择正确的表述。下面是关于不同 `requires` 语句的使用情景:
1. requires com.google.common.truth;:
- 这种情况用于当你的模块需要在运行时和编译时依赖 `com.google.common.truth` 模块。
- 这意味着 `com.google.common.truth` 是你的代码正常运行所必需的,它会被包含在模块路径中,并且在编译和运行时都是可用的。
2. requires truth;:
- 这种情况用于当模块名是 `truth` 而不是 `com.google.common.truth` 时。
- 这通常是因为模块的开发者在 `module-info.java` 文件中定义了模块名为 `truth`。你需要根据实际依赖的模块名来确定使用哪个。
3. requires static com.google.common.truth;:
-