Arrow Function

abhishek p
androidcoding.in
Published in
1 min readMar 29, 2022

We generally use functions in programming such that they serve a purpose and now we will be going to see a new way of declaring them.

So first thing is the new way in declaring will not effect the final output but it will only show the difference in declaration i.e., coding.

In general it might take 3–4 lines of code for declaring a simple addition function like add.

So let’s have a look at the code below

int sum(int a, int b){return a + b;}

So now let’s try to turn down this function into a arrow function

Arrow functions are anonymous functions that are similar to lambda functions in kotlin programming.

Photo by Nick Fewings on Unsplash

The above piece of code when converted to Arrow Function will look similar to this.

int sum(int a, int b)=> a+b;

A single line declaration of function which also makes to code in much cleaner way.

And the important aspect to be noted is we can make a function which has a single implementation into arrow function.

Not all the functions can be arrow functions which have more than one implementation.

More details are provided in the below tutorials may refer if required.

--

--