WEBVTT

00:00.510 --> 00:00.960
Hi everyone.

00:00.960 --> 00:02.460
Welcome back to this tutorial.

00:02.670 --> 00:06.230
In the previous tutorial we discussed the theory part of method reference.

00:06.240 --> 00:12.420
In this tutorial we will code and implement the method reference Using some examples, I'm going to

00:12.420 --> 00:14.040
create a package called.

00:15.580 --> 00:16.750
A third reference.

00:19.050 --> 00:23.460
The first example for method reference is by using the function functional interface.

00:23.730 --> 00:30.870
I'm going to create a class called function method reference.

00:32.890 --> 00:34.960
Sample typo here.

00:34.960 --> 00:36.250
I'm going to change that.

00:38.030 --> 00:38.690
Then.

00:39.570 --> 00:41.190
Let's make this class executable.

00:41.220 --> 00:42.780
Public static, void main.

00:43.590 --> 00:44.160
There we go.

00:44.490 --> 00:48.510
Now, I'm going to use the same example that I showed in the presentation.

00:48.900 --> 00:50.160
Let's make it static.

00:50.920 --> 00:51.520
Function.

00:51.550 --> 00:54.850
This is going to take in a string.

00:57.570 --> 00:59.720
As an input and string as an output.

00:59.730 --> 01:01.140
The function takes two inputs.

01:01.140 --> 01:04.050
One is the input type and second is the output type.

01:04.620 --> 01:06.600
I'm going to name this one first.

01:06.660 --> 01:08.220
Let's code the function.

01:08.250 --> 01:10.200
The name is to.

01:11.770 --> 01:13.270
Her case of lambda.

01:14.710 --> 01:22.000
Equal to basically it is accepting an input and then it performs a uppercase on that input.

01:23.270 --> 01:27.620
You go Now let's check this by passing the input.

01:28.490 --> 01:30.530
Two uppercase lambda dot apply.

01:32.670 --> 01:33.510
Java eight.

01:34.470 --> 01:41.730
If you run, this basically is going to give me the output, but with the uppercase operation on top

01:41.730 --> 01:42.270
of it.

01:42.630 --> 01:43.620
Now.

01:44.370 --> 01:49.920
How do we write the method reference implementation of the same thing?

01:50.930 --> 01:52.670
I'm going to use two uppercase.

01:52.670 --> 01:54.740
I'm going to give a different name.

01:55.430 --> 01:58.340
And then the place of this.

01:59.510 --> 02:01.280
You're going to replace this one with method reference.

02:01.310 --> 02:02.330
We know the syntax.

02:02.690 --> 02:05.960
Class name double colon and then the method name.

02:06.080 --> 02:10.160
So it is class name, double colon and the method name.

02:10.400 --> 02:13.820
See, this is the same implementation as the upper one.

02:14.980 --> 02:16.630
It's a god.

02:18.060 --> 02:20.010
Two uppercase method reference dot apply.

02:20.670 --> 02:22.110
Let's go ahead and run this.

02:23.400 --> 02:23.840
There you go.

02:23.860 --> 02:25.720
Both the output are the same.

02:26.170 --> 02:31.700
Let's see whether IntelliJ is going to help us create these method references.

02:31.720 --> 02:33.900
So click on this lambda expression.

02:33.910 --> 02:34.900
I'm using Mac.

02:34.930 --> 02:38.090
I'm pressing the option Enter key.

02:38.110 --> 02:42.800
As soon as I click that option for Windows, it is Add plus enter as you see in the screen.

02:42.820 --> 02:49.490
As soon as I press those keys, it is giving me this option to replace this lambda with method reference.

02:49.510 --> 02:55.720
As soon as I click it, there you go, It automatically creates a method reference implementation for

02:55.720 --> 02:56.950
the lambda expression.

02:57.190 --> 02:59.170
That's one of the advantages of using IntelliJ.

02:59.440 --> 03:05.410
IntelliJ has the code to convert the lambda expression to the method reference.

03:06.220 --> 03:10.870
This is one of the shortcut which you can use to check whether the lambda expression, whatever you

03:10.870 --> 03:14.590
have in your code is eligible for a method reference or not.

03:14.890 --> 03:20.950
So we have successfully implemented the Lambda expression and the equivalent method reference for that

03:20.950 --> 03:21.400
one.

03:22.180 --> 03:24.110
But thus we came to the end of this tutorial.

03:24.130 --> 03:27.400
Let's take a look at some more examples in the next tutorial.

03:27.790 --> 03:28.150
Thank you for.
