Search code examples
javaclasskotlinclass-constants

Crazy UTF-8 entry in a kotlin class' constant pool


When examining the content of a .class file from a Kotlin source (just "Hello World", nothing else) I found an UTF-8 string within the constant pool that is (a) not used anywhere and (b) with strange content.

Can any tell me what this is?

enter image description here


Solution

  • This is the content of kotlin.Metadata annotation. It is coded with Protobuf and used by both compiler and Kotlin-Reflect.

    Kotlin uses String instead of byte[] because class format is very wasteful at storing arrays.

    When you are not using Kotlin-Reflect, metadata is unused and can be removed by ProGuard.