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

243
Visualizações
Implement code after convert Java to Kotlin error

I already try to found if this problem was here on StackoverFlow, before I came here. I am try to convert a Java class to Kotlin but Android Studio does not do it very well.

I try to do it manually but not success.

This is the original code in Java

    private static void appendHex(StringBuffer sb, byte b) {
        sb.append(HEX.charAt((b >> 4) & 0x0f)).append(HEX.charAt(b & 0x0f));
    }

here is the code converted by Android Studio

    private fun appendHex(sb: StringBuffer, b: Byte) {
        sb.append(HEX[b shr 4 and 0x0f]).append(HEX[b and 0x0f])
    }

the error is after convert, Android Studio does not recognize shr & and, when I press ALT+ENTER it shows a popup to Create extension function Byte.shr and after press enter, it create a this private fun:

private infix fun Byte.shr(i: Int): Any {
    TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

the same to and but now on popup it has an Import option that point to import kotlin.experimental.and or create private fun:

private infix fun Any.and(i: Int): Int {
    TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

after do this and run my app the class is not working with message An operation is not implemented: not implemented

How to implement this to work?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can use the operators (infix functions) shr and and for the type Int (and Long) in Kotlin.
Just change b with b.toInt():

private fun appendHex(sb: StringBuffer, b: Byte) {
    sb.append(HEX[b.toInt() shr 4 and 0x0f]).append(HEX[b.toInt() and 0x0f])
}
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