没有这样的方法错误:ImmutableList.copyOf() [英] no such method error: ImmutableList.copyOf()

查看:182
本文介绍了没有这样的方法错误:ImmutableList.copyOf()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using Guava-05-snapshot, with Sun's JDK 1.6 The code blows up executing this snippet:

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

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

Specifically on the ImmutableList.copyOf() call. This code has worked for months, using the old Google-Collections code.

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

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

The Password.badWords is an ImmutableSet<String> and the creation of the writable array and the sort work perfectly. But attempts to convert the Array into an ImmutableList fail.

推荐答案

番石榴是Google Collections的完全兼容的超集 - 我们没有以不兼容的方式更改任何内容。 (这是通过对最新的番石榴罐运行整个Google Collections测试套件(扩展)来测试的。)

Guava is a fully compatible superset of Google Collections -- we did not change anything in an incompatible way. (This is tested by running the entire Google Collections test suite (which is extensive) against the lastest guava jar.)

我相信你有google-collect - * .jar的副本仍然会进入你的类路径。显式,或者因为其他jar包含它而不重新打包它。您只需要找到并删除它。

I believe you have a copy of google-collect-*.jar still makings its way into your classpath. Either explicitly, or because some other jar included it without repackaging it. You just have to find it and remove it.

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

In Google Collections, there was an ImmutableList.copyOf(Iterable) method, and there was no public ImmutableList.copyOf(Collection) method. Which is fine, because a collection is also an iterable. In Guava, we've added the Collection overload. This is completely compatible, as all source that used to compile still can, and any source previously compiled will simply still reference the original method.

如果编译,问题就会出现反对Guava,然后针对Google Collections。我相信这可能发生了什么。

The problem comes in if you compile against Guava but then run against Google Collections. I believe that is likely what is happening.

这篇关于没有这样的方法错误:ImmutableList.copyOf()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆