Guava 的 Iterables.any() 编译时错误

发布于 12-12 11:02 字数 498 浏览 2 评论 0原文

我收到以下代码的错误:

Iterables.any(Lists.<String>newArrayList(), new Predicate<String>() {
  @Override
  public boolean apply(final String arg0) {
    // TODO Auto-generated method stub
    return false;
  }
});

错误:

类型中的方法any(Iterable, Predicate) Iterables 不适用于参数 (ArrayList, new 谓词(){})

我做错了什么?我觉得我犯了一个愚蠢的错误。

I'm getting an error for the following code:

Iterables.any(Lists.<String>newArrayList(), new Predicate<String>() {
  @Override
  public boolean apply(final String arg0) {
    // TODO Auto-generated method stub
    return false;
  }
});

The error:

The method any(Iterable<T>, Predicate<? super T>) in the type
Iterables is not applicable for the arguments (ArrayList<String>, new
Predicate<String>(){})

What am I doing wrong? I feel like I'm making a silly mistake.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葬花如无物2024-12-19 11:02:04

哎呀 - 我使用了错误的导入。

正确:

import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;

错误:

import com.google.appengine.repackaged.com.google.common.base.Predicate;
import com.google.common.collect.Iterables;

使用重新打包 Guava 会导致问题。

Oops - I was using the wrong import.

Correct:

import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;

Incorrect:

import com.google.appengine.repackaged.com.google.common.base.Predicate;
import com.google.common.collect.Iterables;

Using the repackaged Guava leads to problems.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文