Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

276
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda