【发布时间】:2020-03-30 07:08:42
【问题描述】:
我正在 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
我没有看到与番石榴相关的其他依赖项。
当我检查时:
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 时会自动创建其他版本。
我不知道为什么会发生这种情况。
【问题讨论】:
-
这很奇怪。从 15.0 开始支持这种方法,我试过你的 pom 并且效果很好。
标签: java intellij-idea guava