Java 为什么是番石榴';s Iterables.filter需要谓词中的超类?
为什么番石榴的Java 为什么是番石榴';s Iterables.filter需要谓词中的超类?,java,guava,Java,Guava,为什么番石榴的Iterables.filter需要谓词中的超类 public static <T> Iterable<T> filter(final Iterable<T> unfiltered, final Predicate<? super T> predicate) public static Iterable filter(final Iterable unfiltered,final Predicate您的编译错误是因为您正在将迭代器传
Iterables.filter
需要谓词中的超类
public static <T> Iterable<T> filter(final Iterable<T> unfiltered, final Predicate<? super T> predicate)
public static Iterable filter(final Iterable unfiltered,final Predicate您的编译错误是因为您正在将迭代器
传递给Iterables.filter
,它需要一个Iterable
作为第一个参数。您需要迭代器.filter
这与您的实际问题无关,但因为您提出了以下问题:Iterables.filter
接受一个谓词您的编译错误是因为您正在将一个迭代器
传递给Iterables.filter
,它需要一个Iterable
作为其第一个参数。您需要迭代器.filter
这与您的实际问题无关,但因为您提出了以下问题:Iterables.filter
接受一个谓词您可能希望对谓词(而不是Object)使用某种实类型@RC。谓词
对于该类型来说是好的,如果它只返回false
)一个对每种类型的对象总是返回false的谓词@ColinDPredicates
有一个alwaysFalse()
:p您可能希望为谓词(而不是对象)使用某种实类型@RC<如果该类型只返回false
),则code>Predicate
对于该类型来说是合适的对于每种类型的对象,谓词总是返回false@ColinD谓词
有一个alwaysFalse()
:p
Iterator<TaskSchedule> it = tsp.getAllItems(getCustomerId(), "getId", filter);
com.google.common.collect.Iterables.filter(it, new Predicate<Object>() {
@Override
public boolean apply(Object input)
{
return false;
}
});