2

I have a data class and I am creating an object of it. I am passing parameter values like this:

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!!)

I want to add a value to ApplicationStatus based on if condition. How can I achieve that?

AnderCover
  • 2,488
  • 3
  • 23
  • 42
sagar suri
  • 4,351
  • 12
  • 59
  • 122

1 Answers1

6

It's pretty straightforward:

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

data class TestClass(val text: String)

There's no ternary operator in Kotlin since if is an expression as shown in the simplified example above.

s1m0nw1
  • 76,759
  • 17
  • 167
  • 196