Here’s the method I’m trying to write ( doesn’t compile now, because what is not seen as an Iterable ):
public <T,V> ArrayList<V> mySelect(T what,ITest<V> x) {
ArrayList<V> results = new ArrayList<V>();
for(V value : what) {
if(x.accept(value)) {
results.add(value);
}
}
return results;
}
The T type implements Iterable , and returns V objects when using foreach. The thing is, I don’t know how to write that. Can you help?
The logic behind:
Tis any subclass (implementing class in this case) ofIterable, andthe
Iterableis defined to iterate onVI would recommend reading araqnid’s suggestion, because it shows you how to make your code clearer.