Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

272
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda