kotlin 数据类构造函数内的 if 条件

sag*_*uri 2 kotlin

我有一个data class,我正在创建一个object。我传递这样的参数值:

val leadDetails = AddLeadDetails(AgentId = agent.UserId,
    Name = leadUserName.text.toString().trim(),
    MobileNo = leadMobileNumber.text.toString().trim(),
    ProductType = productTypeId,
    LoanType = productTypeItem,
    ApplicationStatus = //if condition to put value i.e if(string == "s") "One value" else "Second Value"
    Amount = productAmountText.text.toString().trim(),
    Pincode = pinCodeText.text.toString().trim(),
    Remarks = customerRemarks.text.toString().trim(),
    Type = referType!!)
Run Code Online (Sandbox Code Playgroud)

ApplicationStatus我想根据条件添加一个值if。我怎样才能做到这一点?

s1m*_*nw1 6

这非常简单:

fun main(args: Array<String>) {
    TestClass(if (currentTimeMillis() % 2 == 0L) "x" else "y")
}

data class TestClass(val text: String)
Run Code Online (Sandbox Code Playgroud)

Kotlin 中没有三元运算符,因为是一个if表达式,如上面的简化示例所示。