ByteBuddy offers two mechanisms for representing a constant of a Class
that is primitive:
I am aware that the first one creates a "true" dynamic constant in the constant pool. I am aware that the second is specially recognized by ByteBuddy and ultimately results in some other path to storing some sort of class constant in the constant pool. (For example, you can see in the documentation of FixedValue#value(TypeDescription)
that a TypeDescription
will end up being transformed into a constant in the constant pool in some unspecified non-ByteBuddy-specific format that (presumably) is not the same as a dynamic constant.)
I am also aware that ByteBuddy supports JVMs back to 1.5 and that only JDKs of version 11 or greater support true dynamic constants. I am using JDK 15 and personally don't need to worry about anything earlier than that.
Given all this: Should I make constants-representing-primitive-classes using JavaConstant.Dynamic.ofPrimitiveType(Class)
, or should I make them using TypeDescription.ForLoadedType.of(Class)
? Is there some advantage I'm missing to one representation or the other?
Dynamic constants are bootstrapt what causes a minimal runtime overhead. The static constants are therefore likely a better choice but it simplifies your code, there's no danger in using the dynamic ones.