java - newConcurrentHashSet() 无法从 IntelliJ 中的 com.google.guava 解析?

标签 java intellij-idea guava

我正在 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/

相关文章:

git - IntelliJ 中与 'Default Task' 关联的分支

graph - Guava ValueGraph 的简单示例

java - 如果使用来自 Guava 的 com.google.common,为什么不应该使用 Objects.requireNonNull()?

java - Guava ImmutableMap 中的性能警告

java - 动态创建图形常量

java - Java中是否有静态初始化器的对立工具

java - DBUtils QueryRunner 在重复键更新时插入

android - Android Studio : White Space Formatting Strategy Factory error

java - 有关 Java XML 生态系统概述的好引用资料?

java - 如何从 intellij 项目 View 中隐藏不必要的文件?