gpt4 book ai didi

java - 没有这样的方法错误 : ImmutableList. copyOf()

转载 作者:IT老高 更新时间:2023-10-28 21:03:05 26 4
gpt4 key购买 nike

我正在使用 Guava-05-snapshot 和 Sun 的 JDK 1.6执行此代码段的代码会爆炸:

List<String> badpasswords = Lists.newArrayList( Password.badWords);
Collections.sort(badpasswords);
ImmutableList<String> tmp = ImmutableList.copyOf(badpasswords);

特别是在 ImmutableList.copyOf() 调用上。此代码使用旧的 Google-Collections 代码已经工作了几个月。

java.lang.NoSuchMethodError: com.google.common.collect.ImmutableList.copyOf(Ljava/util/Collection;)Lcom/google/common/collect/ImmutableList;

Password.badWordsImmutableSet<String>并且可写数组的创建和排序工作完美。但尝试将数组转换为 ImmutableList失败。

最佳答案

Guava 是完全兼容的 Google Collections 超集——我们没有以不兼容的方式更改任何内容。 (这是通过针对最新的 guava jar 运行整个 Google Collections 测试套件(广泛)来测试的。)

我相信您的类路径中仍有一份 google-collect-*.jar 的副本。要么是明确的,要么是因为其他一些 jar 包含它而没有重新打包它。你只需要找到它并删除它。

在 Google Collections 中,有一个 ImmutableList.copyOf(Iterable) 方法,没有公共(public) ImmutableList.copyOf(Collection) 方法。这很好,因为集合也是可迭代的。在 Guava 中,我们添加了 Collection 重载。这是完全兼容的,因为所有用于编译的源代码仍然可以,并且任何先前编译的源代码仍将简单地引用原始方法。

如果您针对 Guava 进行编译,然后针对 Google Collections 运行,就会出现问题。我相信这很可能正在发生。

关于java - 没有这样的方法错误 : ImmutableList. copyOf(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3126330/

26 4 0