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

894
Vistas
"No set method providing array access" -- why does this happen in Kotlin?

Here's the code.

val stack = Array(inputString.length + 1) { "" }
var current = 0
for ((i, char) in inputString.withIndex()) {
    if (char == '(') {
        current += 1
        continue
    } else if (char == ')') {
        val enclosedString = stack[current]
        stack[current - 1] = stack[current - 1] + enclosedString.reversed()
        current -= 1
        continue
    } else {
        stack[current] +=  char //here's the compile time error 
    }
}

I'm getting an error saying "No set method providing array access". I don't understand this.

If I change it to:

stack[current] = stack[current] + char

things work fine.

Why is this happening?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The cause of the error is the incorrect assignment of a Char variable to an Array<String>, you need to convert the Char to String before, and that's what is happening in the statement

stack[current] = stack[current] + char

The + function returns a new String concatenating with the string representation of the right side (i.e. it automatically call toString in the right operand). In other words, it is converting the Char variable char to String before the concatenation.

You can also convert it yourself.

stack[current] += char.toString()
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