Search code examples
jvmbytecodebytecode-manipulation

How does ldc turn a sequence of characters into a String object?


In java bytecode a string constant is stored in the constant pool as a sequence of characters. I'm curious as to how the jvm converts that into a string object and if there's a way to take advantage of that for other object types that you want stored in the constant pool.


Solution

  • This is an implementation detail, and no you can't take advantage of it for other types.

    Most likely, it just goes through the utf8info, decodes everything into utf16 code points, and allocates them in an array somewhere. It's not rocket science.