Java 8 also introduces method references and allows them to be used anywhere a Functional Interface AKA Single Abstract Method is expected.
Up until now we've been using anonymous functions.
But it's also possible to use a thing called method references.
And we can use those in place of where lambdas are expected.
you, which we'll explore in depth in a different course.
as it's probably the correct way to solve this using functions.
It may also be a little hard to read if it's new to you.
and let's replace this with using method references.
So let's go ahead, let's do this.
So, Comparator,comparing the static method and it expects a function.
We could put a lambda here right?
So we could do this we could say b and b.getTitle.
So what that does is it says for each thing in here compare using the title.
So, that's a lot cleaner already using that lambda method.
But since that style is so common, you can actually do something like this.
you can actually use a method reference.
has a method called getTitle on it, and it should use that.
This takes a little bit to get use to, but it's super powerful.
Now it also works with parameters.
And the method that we want to do, cuz it takes a parameter, is println.
for each applies the entry as the parameter to the function.
But it's definitely gonna take some time to get used to.
But don't let that boggle your mind too much.
We'll go over that fully in a functional programming course.
But I just wanted you to see that double colon style of method reference.
Okay, so let's take a quick look at the evolution of our code.
So, here is the SAM method, right?
Okay, so let's expand this.
And again, so this creates a new anonymous class.
We had to put the override with the method name, and we defined the method.
And we put in there return type, pretty noisy.
And then it got cleaner.
We still had the types.
And then it got a lot cleaner, right.
So we removed all the return lines, and now it's onto three lines.
See how much cleaner things can become?
So, there you go, I hope you're happy.
Oh no, no wait, I hope you are merry that you had a little into to lambdas.
Mary had a little lambda?
Oh God, you should edit that joke out, it's so bad.
>> So there we go.
I'm glad you got a chance to meet and get cozy with lambda expressions.
new java code and frame works.
please be sure to check out the teachers notes for more resources.
how we can make it even better.
make sure your vote is heard on upcoming content.
Thanks for hanging out and we'll see you very soon.