作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个自定义谓词,其签名如下:
public class ELPredicate<T> implements Predicate<T>
我正尝试在类似于此的函数中过滤它们:
public List<ComponentDefinition> filterComponents(String expression, List<ComponentDefinition> definitions) {
if (definitions == null || definitions.size() == 0) {
return new ArrayList<ComponentDefinition>();
}
ELPredicate<ComponentDefinition> predicate = new ELPredicate<>(expression);
return Lists.newArrayList(Iterables.filter(definitions, predicate));
}
但是我得到这个错误:
The method filter(Iterable<T>, Predicate<? super T>) in the type Iterables is not applicable for the arguments (List<ComponentDefinition>, ELPredicate<ComponentDefinition>)
据我所知(我认为):
<ComponentDefinition>
是<? super ComponentDefinition>
这是怎么回事?
最佳答案
事实证明,我的问题是访问问题而不是类型问题。我试图过滤一个私有(private)内部类(用于测试目的),而 java 显然不喜欢那样。我将其公开,一切都按预期进行。
关于java - Google guava iterables.filter,与泛型相关的类型错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17457922/
我是一名优秀的程序员,十分优秀!