我有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!!)
我想根据ApplicationStatus
条件向if
添加值。我怎样才能做到这一点?
答案 0 :(得分:4)
这很简单:
fun main(args: Array<String>) {
TestClass(if (currentTimeMillis() % 2 == 0L) "x" else "y")
}
data class TestClass(val text: String)
Kotlin中有no ternary operator,因为if
是一个表达式,如上面的简化示例所示。