我正在 macbook 上的 IntelliJ(社区 2019.2)中编译 java。
我的代码:
import com.google.common.collect.Sets;
public static void main(String[] args) {
Sets.newConcurrentHashSet();// error ! cannot resolve the method !
}
我的pom:
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency>
</dependencies>
基于
https://github.com/google/guava/blob/master/guava/src/com/google/common/collect/Sets.java
Sets.newConcurrentHashSet();
应该可用。
但是,为什么我不能调用它?
更新 我已经跑了
mvn dependency:tree
得到:
+- com.google.guava:guava:jar:28.1-jre:compile
[INFO] | +- com.google.guava:failureaccess:jar:1.0.1:compile
[INFO] | +- com.google.guava:listenablefuture:jar:9999.0-empty-to- avoid-conflict-with-guava:compile
我没有看到与 Guava 相关的其他依赖项。
当我检查时:
ls -lrt ~/.m2/repository/com/google/guava/guava
我明白了:
28.1-jre
14.0.1
16.0.1
19.0
12.0.1
11.0.2
27.0-jre
虽然我删除了除 28.1-jre 之外的所有其他版本,但每当我编译项目或打开 IntelliJ 时,都会自动创建其他版本。
我不知道为什么会发生这种情况。
最佳答案
请使用以下依赖项。
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.1-jre</version>
</dependency>
</dependencies>
希望这会起作用。
关于java - newConcurrentHashSet() 无法从 IntelliJ 中的 com.google.guava 解析?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60925596/