example 1: Here, since it is static method we are passing argument 'l'. ?
Nothing static here. You may call it like this:
to get the list sorted.
Here, you have a closure over a variable named
str of type
String. You may call it as follows:
The third one is obvious.
Note that although you may declare and call lambdas as indicated, it makes no sense. Generally, lambdas will be used as parameters for methods or functions. Also note that when you write:
you are creating an object of type
Predicate. This is equivalent to:
Lambdas are not primarily intended to create objects, but to be use anonymously, such as:
In such a case, no
Predicate instance is ever created. But the most efficient way to write this is to use a method reference: