Hi ,
In this post I will share the information about "TailRec Functions"
This function helps us to use recursion in more optimised way.
We all know , that recursion means , calling its own function from within the function, and this recursion if the function has been called 100 or 1000 times , then in Java or C programming language , we may face the StackOverflowException .
But in Kotlin this recursion has been done with the help of TailRec Function, which prevents the "StackOverflowException" .
Let's have a look :
Like this , we can use the recursion function in a better way in Kotlin.
In this post I will share the information about "TailRec Functions"
This function helps us to use recursion in more optimised way.
We all know , that recursion means , calling its own function from within the function, and this recursion if the function has been called 100 or 1000 times , then in Java or C programming language , we may face the StackOverflowException .
But in Kotlin this recursion has been done with the help of TailRec Function, which prevents the "StackOverflowException" .
Let's have a look :
tailrec private fun getPrint() { println("Hello All") getPrint() }
Like this , we can use the recursion function in a better way in Kotlin.
No comments:
Post a Comment