How To Define Default Value In Function Parameter In Kotlin?

Forums AndroidHow To Define Default Value In Function Parameter In Kotlin?
Staff asked 3 years ago

Answers (1)

Add Answer
Karan Rajgor Marked As Accepted
Staff answered 2 years ago

I’ve provided answer below

fun main() {
    test(20);
    //println("Hello, world!!!")
}

fun test(length: Int = 15){
    if(length != 0){
    	println(length)    
    }
    else
    {
        println("Hello, world!!!")
    }
    
}

 

Subscribe

Select Categories