본문 바로가기

Kotlin

#7.8 Kotlin INFIX FUNCTION. Kotlin Tutorials for Beginners for Android

fun main(args: Array<String>){
    val x: Int = 5
    val y: Int = 6

    val greatVal = x greaterValue y // x.greatValue(y)

    println(greatVal)
}



infix fun Int.greaterValue(other: Int): Int{ // Infix function and also Extension func
    if (this > other)
        return this
    else
        return other
}

/*
* 1. All infix functions are extension function
* But all extensiong function are not Infix
* 2. Infix functions just have one parameter
 */

 

youtu.be/ikUF1z_WOZc