我尝试过滤AddReport
但是当在Predicate体中放置一个断点时,我看到那里没有执行代码。
懒惰吗?我看到各种各样的子类。
不只是AddReport
Iterable<BaseClass> filtered =
Iterables.filter(myList,
new Predicate<BaseClass>() {
@Override
public boolean apply(@Nullable BaseClass input) {
AddReport addReport = (AddReport) input;
return ((addReport != null) && addReport.description.equals(messageBody));
}
});
Collection<BaseClass> filtered2
= Collections2.filter(myList,
new Predicate<BaseClass>() {
@Override
public boolean apply(@Nullable BaseClass input) {
AddReport addReport = (AddReport) input;
return ((addReport != null) && addReport.description.equals(messageBody));
}
});
答案 0 :(得分:0)
听起来我想你想要的是首先将你的迭代过滤到只有AddReport
的实例,你可以这样做:
Iterable<AddReport> addReports = Iterables.filter(myList, AddReport.class);