As it turns out, my problem was an access issue rather than a type issue. I was attempting to filter a private inner class (for testing purposes) and java apparently doesn't like that. I made it public and everything worked as expected.
Google guava iterables.filter, type errors related to generics?
Question
I have a custom predicate that has a signiture as follows:
public class ELPredicate<T> implements Predicate<T>
I am attempting to filter them in a function similar to this:
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));
}
but i get this error:
The method filter(Iterable<T>, Predicate<? super T>) in the type Iterables is not applicable for the arguments (List<ComponentDefinition>, ELPredicate<ComponentDefinition>)
from what (I think) I know:
- Lists are iterable,
<ComponentDefinition>
is<? super ComponentDefinition>
- I am doing this in unit tests without any problem.
what's going on?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow