Groovy String.resolveConstantDesc
Resolve a String constant descriptor using the standard constant-description API.
A simple example
String.resolveConstantDesc
- Start with The string constant "A"
- Do this Resolve its description
- Result "A"
Syntax
public String resolveConstantDesc(MethodHandles.Lookup lookup)
Run these examples in Groovy
Save one example at a time as Lesson.groovy. Use Groovy 4 on JDK 21.
groovy Lesson.groovyResolve a label for a JVM tool
A JVM inspection tool needs a runtime label from a symbolic constant. Supply the lookup context and examine the resolved text before presenting it to the user.
println "Gate B".resolveConstantDesc(java.lang.invoke.MethodHandles.lookup())
Gate B
String resolves to its own value.
Verify descriptor identity
A JVM tool receives a descriptor for a constant string and has to resolve it in a lookup context. Follow the resolved value through the example to see what the tool can use after that step.
String name = "Lab"
println name.is(name.resolveConstantDesc(java.lang.invoke.MethodHandles.lookup()))
true
Resolution preserves the receiver identity.
Read a parcel sorting code
The depot scans a parcel marked NC-17. The program recovers the text of this existing string for a scanner log. What exact sequence of characters should survive?
What to watch for
String is its own resolved constant. Other descriptor types may perform lookups and have different failure modes.