Error
The method forEach(Consumer<? super Integer>) in the type Iterable<Integer> is not applicable for the arguments (Predicate<String>)
while using forEach and Lambda Expressions in Java 8.
Error Type
Compile Time ( Java 8 )
Sample Code
Predicate<Integer> prd = p->p.charAt(0)>65;
intList.forEach(prd);
Cause
forEach method expects a Consumer and not Predicate.
Resolution
Provide a Consumer as an argument to forEach
Consumer<Integer> cnr = p->System.out.println("Consumer");
intList.forEach(cnr);
The method forEach(Consumer<? super Integer>) in the type Iterable<Integer> is not applicable for the arguments (Predicate<String>)
while using forEach and Lambda Expressions in Java 8.
Error Type
Compile Time ( Java 8 )
Sample Code
Predicate<Integer> prd = p->p.charAt(0)>65;
intList.forEach(prd);
Cause
forEach method expects a Consumer and not Predicate.
Resolution
Provide a Consumer as an argument to forEach
Consumer<Integer> cnr = p->System.out.println("Consumer");
intList.forEach(cnr);