当前位置:网站首页>Infix keyword infix expression and the use of generic extension function in kotlin

Infix keyword infix expression and the use of generic extension function in kotlin

2022-07-07 08:14:00 yu-Knight

// Conditions for a : The first parameter is  T.go  Function extension 
// Condition 2 : Need to be in parentheses (r:R) Pass a parameter in the parameter 
private infix fun <T, R> T.go(r: R) {
    println(" Infix expression , The content of the first parameter is :$this")
    println(" Infix expression , The content of the second parameter is :$r")
}

fun main(){
    //map Infix expression in 
    mapOf("map1" to 1)
    mapOf("map2" to 2)
    mapOf("map3" to 3)
    // Infix expression written by myself 
    123 go "String"
    "yuknight" go "kotlin"
}

原网站

版权声明
本文为[yu-Knight]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130641028462.html