Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

270
Views
Changing value of variable inside argument in kotlin

In Java you can do the following:

boolean a = true;
if(a = false) {
   //////
}

And a will be set to false and be used after that as argument. But in kotlin, I couldn't find a way to do that, except for:

var a = true
a = false
if(a) {

}

Is there any better way?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can do this inline in a slightly different order - by writing the value to be assigned (false) first, and using the also scope function to assign it:

var a = true
if(false.also { a = it }) {

}

However, I would not recommend you to do this in either Java or Kotlin, as this is not very readable. There is nothing bad about writing the assignment as a separate statement.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!