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

323
Vistas
Kotlin does not allow charAt

Why java compiles when kotlin not? And how to invoke charAt in kotlin?

Java:

import java.nio.CharBuffer;

public class Test {
    public static void test() {
        CharBuffer buffer = CharBuffer.wrap("asd");
        buffer.charAt(0);
    }
}

Kotlin:

import java.nio.CharBuffer

class TestKotlin {
    fun test() {
        val buffer = CharBuffer.wrap("asd")
        buffer.charAt(0)
    }
}
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I am theorizing from looking at this old issue that the Kotlin developers at one time accidentally treated CharBuffer.charAt() and CharBuffer.get() as equivalent and hid the charAt() method in Kotlin and mapped it to get(). They might have done this in an effort to promote the use of array-access syntax (brackets) and avoid supposed redundancy.

And perhaps later when the above issue was fixed, they missed unhiding the method.

buffer.charAt(i) would be buffer[buffer.position() + i] in Kotlin. You could write an extension function so you can continue to use it:

fun CharBuffer.charAt(index: Int) = this[position() + index]

The error message if you choose an out-of-bounds index will be slightly less informative than the one in the original method.

Maybe someone should open an issue on YouTrack for this...

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