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

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

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 Denunciar

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 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