bootstrapArgsList(): This method is available in the java.lang.constant.DynamicConstantDesc class of Java.
Syntax:
List<ConstantDesc> java.lang.constant.DynamicConstantDesc.bootstrapArgsList()
This method returns the bootstrap arguments for this constant as an immutable List.
Parameters: NA
Returns: a List of the bootstrap arguments.
Exceptions: NA
Approach
Java
package com.DynamicConstantDesc;import java.lang.constant.ClassDesc;import java.lang.constant.ConstantDescs;import java.lang.constant.DirectMethodHandleDesc;import java.lang.constant.DynamicConstantDesc;import java.lang.constant.MethodTypeDesc;import java.lang.invoke.MethodHandles.Lookup;public class DynamicConstantDescbootstrapArgsList {public static void main(String[] args) {DirectMethodHandleDesc bootstrapMethod = new DirectMethodHandleDesc() {@Overridepublic Object resolveConstantDesc(Lookup lookup) throws ReflectiveOperationException {return "hello";}@Overridepublic MethodTypeDesc invocationType() {return MethodTypeDesc.of(ClassDesc.of("hello"), ClassDesc.of("hello"));}@Overridepublic int refKind() {return 5;}@Overridepublic ClassDesc owner() {return ClassDesc.of("hello");}@Overridepublic String methodName() {return "hello";}@Overridepublic String lookupDescriptor() {return "loolup";}@Overridepublic Kind kind() {return Kind.CONSTRUCTOR;}@Overridepublic boolean isOwnerInterface() {return true;}};DynamicConstantDesc<?> dynamicConstantDesc = DynamicConstantDesc.ofNamed(bootstrapMethod, "name",ClassDesc.of("name"), ConstantDescs.BSM_ENUM_CONSTANT);System.out.println(dynamicConstantDesc.bootstrapArgsList());}}
Output:
[MethodHandleDesc[STATIC/ConstantBootstraps::enumConstant(MethodHandles$Lookup,String,Class)Enum]]
Some other methods of DynamicConstantDesc
DynamicConstantDesc.ofNamed(DirectMethodHandleDesc, String, ClassDesc, ConstantDesc...): This method returns a nominal descriptor for a dynamic constant.
bootstrapArgs(): This method returns the bootstrap arguments for this constant.
bootstrapArgsList(): This method returns the bootstrap arguments for this constant as an immutable List.
bootstrapMethod(): This method returns a MethodHandleDesc describing the bootstrap method for this constant.
constantName(): This method returns the name that would appear in the NameAndType operand of the LDC for this constant.
constantType(): This method returns a ClassDesc describing the type that would appear in the NameAndType operand of the LDC for this constant.
equals(Object): This method compares the specified object with this descriptor for equality. Returns true if and only if the specified object is also a DynamicConstantDesc, and both descriptors have equal bootstrap methods, bootstrap argument lists, constant name, and constant type.
hashCode(): This method returns a hash code value for the object.
DynamicConstantDesc.of(DirectMethodHandleDesc): This method returns a nominal descriptor for a dynamic constant whose bootstrap has no static arguments, and whose name parameter is ConstantDescs.DEFAULT_NAME, and whose type parameter is always the same as the bootstrap method return type.
DynamicConstantDesc.of(DirectMethodHandleDesc, ConstantDesc...): This method returns a nominal descriptor for a dynamic constant whose name parameter is ConstantDescs.DEFAULT_NAME, and whose type parameter is always the same as the bootstrap method return type.
DynamicConstantDesc.ofCanonical(DirectMethodHandleDesc, String, ClassDesc, ConstantDesc[]): This method returns a nominal descriptor for a dynamic constant, transforming it into a more specific type if the constant bootstrap is a well-known one and a more specific nominal descriptor type (e.g., ClassDesc) is available.
resolveConstantDesc(Lookup): This method resolves this descriptor reflectively, emulating the resolution behavior of JVMS 5.4.3 and the access control behavior of JVMS 5.4.4. The resolution and access control context is provided by MethodHandles.Lookupparameter. No caching of the resulting value is performed.
toString(): This method returns a compact textual description of this constant description, including the bootstrap method, the constant name and type, and the static bootstrap arguments.
No comments:
Post a Comment