Incompatible types: The predicate <CAP # 1> cannot be converted to Predicate <? Super CAP # 2>
Here is my code.
import java.util.stream.Stream;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.function.Predicate;
public class StreamMethod{
public static void main(String... args){
List<Integer> data = new ArrayList<Integer>(Arrays.asList(1,2,3,4,5,6,7,8));
allMatch(data, x -> x < 10);
}
public static <T> void allMatch(List<?> list, Predicate<? super T> predicate){
boolean allSatisfy = list.stream().allMatch(predicate);
System.out.println(allSatisfy);
}
}
I get an error message incompatible types: Predicate<CAP#1> cannot be converted to Predicate<? super CAP#2>
. Can you help me solve this problem? and why does he show this error?
Then I also modify the above lines of passing arguments as
Predicate<Integer> pred= x -> x < 10;
allMatch(data, pred);
But still facing an error.
+4