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

159
Views
Enfoque de Kotlin para realizar una operación después de ejecutar cualquiera de los bloques de condición

¡Conociendo a Kotlin!

 var flag = false; if(condition) { //do one thing flag = true; } if(condition2) { //do another thing flag = true; } if(flag) save();

¿Cuál es la forma correcta de hacer esto en Kotlin evitando el enfoque de flag ?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

No veo ninguna forma inteligente de hacerlo de manera concisa en Kotlin, pero en la mayoría de los casos, probablemente preferiría asignar condiciones a las variables en lugar del enfoque de flag :

 val isBlue = ... some condition ... val hasWings = ... another condition ... if (isBlue) { ... } if (hasWings) { ... } if (isBlue || hasWings) { ... }

Por supuesto, es una cuestión de gusto personal.

Además, en algunos casos flag tiene más sentido. Hay save() en su ejemplo, por lo que si este indicador es algo así como shouldSaveData y depende de varias condiciones en las que, por ejemplo, los datos están mutados, entonces el enfoque del flag tiene mucho sentido.

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!