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

218
Visualizações
Name Shadowing in kotlin

Recently, I face this warning in my IntelliJ Idea. But I don't have any solution for that... Also, I don't want to use the @Suppress("NAME_SHADOWING"). I'll be grateful if you guide me. This is my code:

fun add(
    @Parameter id: Long?
): someClass {
    myTable?.content?.firstOrNull { it.add }?.id?.let { id ->
        db.products.readById(id)?.let { db.products.delete(it) }
    }
    return remove(id)
}
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Name shadowing means that you are using variables with the same name in different scopes, making it more likely that you by accident refer to the wrong one. The solution is to rename them to be different. In your case it's the variable id. It is both the parameter of the function and it is also defined after the first let. So you could for example do this to remove the warning:

fun add(
    @Parameter id: Long?
): someClass {
    myTable?.content?.firstOrNull { it.add }?.id?.let { id2 ->
        db.products.readById(id2)?.let { db.products.delete(it) }
    }
    return remove(id)
}
over 4 years ago · Santiago Trujillo Relatório

0

fun add(
    @Parameter id: Long?
): someClass {
    myTable?.content?.firstOrNull { it.add }?.id
        ?.let { id ->
            // Here you have two variables named "id" (the other being the function parameter)
            db.products.readById(id)?.let { db.products.delete(it) }
        }
    return remove(id)
}

Simply rename one of the parameters and the warning will go away.

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