Tried to replace lambdas with anonymous class in Stream API (below code) and it works fine. I want to understand how the parameter required for the test(T t) method is getting generated from.
Lambda
list.stream()
.map(String::length)
.filter(t->t>4).count();
Anonymous class
list.stream()//line1
.map(String::length)
.filter(new Predicate<Integer>() {
@Override
public boolean test(Integer t) {//line 5
return t>4;
}
}).count();
While using lambdas we pass the parameter using the lambda notation, but I dont understand how the Integer t
at line 5 is getting generated from. Is it due to the Fluent API
in Stream
or due to the functional interface(lambda)?
Edit : I am clear about lambda
version, dont understand how the version with anonymous class
is working? To put in another way, would it work in Java 1.7
(provided we wrote something similar to Stream API
, we just wont have lambdas).
Edit : For anyone confused like I was, please look at https://github.com/fmcarvalho/quiny , simplified implementation of Stream API by some smart guy