在 Kotlin 中编写以下代码段的简洁方法是什么

Pub*_*nda 0 if-statement kotlin

我正在学习 Kotlin,并且我用 Kotlin 编写了以下代码片段。除了使用 if-else 条件之外,还有什么简洁的方法可以编写以下代码吗?

fun test(a: int, b: int): Coding {
   return Coding().apply{
    if(a>b){
     comment = "first value greater than second value"
     value = a
    }else{
     comment = "second value greater than or equal to first value"
     value = b
    }  
   }
}
Run Code Online (Sandbox Code Playgroud)

luk*_*s.j 5

comment = if (a > b) "first value grater than second value" else "second value grater than or equal to first value"
value = max(a, b)
Run Code Online (Sandbox Code Playgroud)