Friday 17 April 2020

Kotlin : TailRec Functions (Post 11)

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 :

 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

Advanced Kotlin Coroutines : Introduction

 Hi,  Today I am unwraping the topic in Kotin world i.e. Coroutine . If you want to get started with Kotlin coroutine and ease your daily de...