ConstantDescs class in Java

java.lang.constant.ConstantDescs

Predefined values of nominal descriptors for common constants, including descriptors for primitive class types and other common platform types, and descriptors for method handles for standard bootstrap methods.

1. ConstantDescs.BSM_ENUM_CONSTANT

DirectMethodHandleDesc java.lang.constant.ConstantDescs.BSM_ENUM_CONSTANT

MethodHandleDesc representing ConstantBootstraps.enumConstant

2. ConstantDescs.BSM_EXPLICIT_CAST

DirectMethodHandleDesc java.lang.constant.ConstantDescs.BSM_EXPLICIT_CAST

MethodHandleDesc representing ConstantBootstraps.explicit Cast(Lookup, String, Class, Object) ConstantBootstraps.explicitCast}.

3. ConstantDescs.BSM_GET_STATIC_FINAL

DirectMethodHandleDesc java.lang.constant.ConstantDescs.BSM_GET_STATIC_FINAL

MethodHandleDesc representing ConstantBootstraps.getStaticFinal.

4. ConstantDescs.BSM_INVOKE

DirectMethodHandleDesc java.lang.constant.ConstantDescs.BSM_INVOKE

MethodHandleDesc representing ConstantBootstraps.invoke.

5. ConstantDescs.BSM_NULL_CONSTANT

DirectMethodHandleDesc java.lang.constant.ConstantDescs.BSM_NULL_CONSTANT

MethodHandleDesc representing ConstantBootstraps.null constant.

6. ConstantDescs.BSM_PRIMITIVE_CLASS

DirectMethodHandleDesc java.lang.constant.ConstantDescs.BSM_PRIMITIVE_CLASS

MethodHandleDesc representing ConstantBootstraps.primitive class.

7. ConstantDescs.BSM_VARHANDLE_ARRAY

DirectMethodHandleDesc java.lang.constant.ConstantDescs.BSM_VARHANDLE_ARRAY

MethodHandleDesc representing ConstantBootstraps.arrayVarHandle.

8. ConstantDescs.BSM_VARHANDLE_FIELD

DirectMethodHandleDesc java.lang.constant.ConstantDescs.BSM_VARHANDLE_FIELD

MethodHandleDesc representing ConstantBootstraps.fieldVarHandle

9. ConstantDescs.BSM_VARHANDLE_STATIC_FIELD

DirectMethodHandleDesc java.lang.constant.ConstantDescs.BSM_VARHANDLE_STATIC_FIELD

MethodHandleDesc representing ConstantBootstraps.staticVarHandle.

Approach

Java

package com.ConstantDescs;

import java.lang.constant.ConstantDescs;

public class ConstantDescs1 {
    public static void main(String[] args) {

        System.out.println(ConstantDescs.BSM_ENUM_CONSTANT);
        System.out.println(ConstantDescs.BSM_EXPLICIT_CAST);
        System.out.println(ConstantDescs.BSM_GET_STATIC_FINAL);
        System.out.println(ConstantDescs.BSM_INVOKE);
        System.out.println(ConstantDescs.BSM_NULL_CONSTANT);

        System.out.println(ConstantDescs.BSM_PRIMITIVE_CLASS);
        System.out.println(ConstantDescs.BSM_VARHANDLE_ARRAY);
        System.out.println(ConstantDescs.BSM_VARHANDLE_FIELD);
        System.out.println(ConstantDescs.BSM_VARHANDLE_STATIC_FIELD);
    }
}

Output

MethodHandleDesc[STATIC/ConstantBootstraps::enumConstant(MethodHandles$Lookup,String,Class)Enum] MethodHandleDesc[STATIC/ConstantBootstraps::explicitCast(MethodHandles$Lookup,String,Class,Object)Object] MethodHandleDesc[STATIC/ConstantBootstraps::getStaticFinal(MethodHandles$Lookup,String,Class,Class)Object] MethodHandleDesc[STATIC/ConstantBootstraps::invoke(MethodHandles$Lookup,String,Class,MethodHandle,Object[])Object] MethodHandleDesc[STATIC/ConstantBootstraps::nullConstant(MethodHandles$Lookup,String,Class)Object] MethodHandleDesc[STATIC/ConstantBootstraps::primitiveClass(MethodHandles$Lookup,String,Class)Class] MethodHandleDesc[STATIC/ConstantBootstraps::arrayVarHandle(MethodHandles$Lookup,String,Class,Class)VarHandle] MethodHandleDesc[STATIC/ConstantBootstraps::fieldVarHandle(MethodHandles$Lookup,String,Class,Class,Class)VarHandle] MethodHandleDesc[STATIC/ConstantBootstraps::staticFieldVarHandle(MethodHandles$Lookup,String,Class,Class,Class)VarHandle]


1. ConstantDescs.CD_boolean

ClassDesc java.lang.constant.ConstantDescs.CD_boolean

ClassDesc represents the primitive type boolean.

2. ConstantDescs.CD_Boolean

ClassDesc java.lang.constant.ConstantDescs.CD_Boolean

ClassDesc representing Boolean.

3. ConstantDescs.CD_byte

ClassDesc java.lang.constant.ConstantDescs.CD_byte

ClassDesc represents the primitive type byte.

4. ConstantDescs.CD_Byte

ClassDesc java.lang.constant.ConstantDescs.CD_Byte

ClassDesc representing Byte.

5. ConstantDescs.CD_CallSite

ClassDesc java.lang.constant.ConstantDescs.CD_CallSite

ClassDesc representing CallSite.

6. ConstantDescs.CD_char

ClassDesc java.lang.constant.ConstantDescs.CD_char

ClassDesc represents the primitive type char.

7. ConstantDescs.CD_Character

ClassDesc java.lang.constant.ConstantDescs.CD_Character

ClassDesc representing Character.

8. ConstantDescs.CD_Class

ClassDesc java.lang.constant.ConstantDescs.CD_Class

ClassDesc representing Class.

9. ConstantDescs.CD_ClassDesc

ClassDesc java.lang.constant.ConstantDescs.CD_ClassDesc

ClassDesc representing ClassDesc

10. ConstantDescs.CD_Collection

ClassDesc java.lang.constant.ConstantDescs.CD_Collection

ClassDesc representing Collection.

Approach

Java

package com.ConstantDescs;

import java.lang.constant.ConstantDescs;

public class ConstantDescs2 {
    public static void main(String[] args) {

        System.out.println(ConstantDescs.CD_boolean);
        System.out.println(ConstantDescs.CD_Boolean);
        System.out.println(ConstantDescs.CD_byte);
        System.out.println(ConstantDescs.CD_Byte);

        System.out.println(ConstantDescs.CD_CallSite);
        System.out.println(ConstantDescs.CD_char);
        System.out.println(ConstantDescs.CD_Character);
        System.out.println(ConstantDescs.CD_Class);
        System.out.println(ConstantDescs.CD_ClassDesc);
        System.out.println(ConstantDescs.CD_Collection);

    }
}

Output

PrimitiveClassDesc[boolean] ClassDesc[Boolean] PrimitiveClassDesc[byte] ClassDesc[Byte] ClassDesc[CallSite] PrimitiveClassDesc[char] ClassDesc[Character] ClassDesc[Class] ClassDesc[ClassDesc] ClassDesc[Collection]


1. ConstantDescs.CD_ConstantBootstraps

ClassDesc java.lang.constant.ConstantDescs.CD_ConstantBootstraps

ClassDesc representing ConstantBootstraps

2. ConstantDescs.CD_ConstantDesc

ClassDesc java.lang.constant.ConstantDescs.CD_ConstantDesc

ClassDesc representing ConstantDesc

3. ConstantDescs.CD_DirectMethodHandleDesc

ClassDesc java.lang.constant.ConstantDescs.CD_DirectMethodHandleDesc

ClassDesc representing DirectMethodHandleDesc

4. ConstantDescs.CD_double

ClassDesc java.lang.constant.ConstantDescs.CD_double

ClassDesc represents the primitive type double

5. ConstantDescs.CD_Double

ClassDesc java.lang.constant.ConstantDescs.CD_Double

ClassDesc representing Double

6. ConstantDescs.CD_DynamicCallSiteDesc

ClassDesc java.lang.constant.ConstantDescs.CD_DynamicCallSiteDesc

ClassDesc representing DynamicCallSiteDesc

7. ConstantDescs.CD_DynamicConstantDesc

ClassDesc java.lang.constant.ConstantDescs.CD_DynamicConstantDesc

ClassDesc representing DynamicConstantDesc

8. ConstantDescs.CD_Enum

ClassDesc java.lang.constant.ConstantDescs.CD_Enum

ClassDesc representing Enum

9. ConstantDescs.CD_EnumDesc

ClassDesc java.lang.constant.ConstantDescs.CD_EnumDesc

ClassDesc representing EnumDesc

10. ConstantDescs.CD_Exception

ClassDesc java.lang.constant.ConstantDescs.CD_Exception

ClassDesc representing ExceptionClassDesc

Approach

Java

package com.ConstantDescs;

import java.lang.constant.ConstantDescs;

public class ConstantDescs3 {
    public static void main(String[] args) {

        System.out.println(ConstantDescs.CD_ConstantBootstraps);
        System.out.println(ConstantDescs.CD_ConstantDesc);
        System.out.println(ConstantDescs.CD_DirectMethodHandleDesc);
        System.out.println(ConstantDescs.CD_double);
        System.out.println(ConstantDescs.CD_Double);

        System.out.println(ConstantDescs.CD_DynamicCallSiteDesc);
        System.out.println(ConstantDescs.CD_DynamicConstantDesc);
        System.out.println(ConstantDescs.CD_Enum);
        System.out.println(ConstantDescs.CD_EnumDesc);
        System.out.println(ConstantDescs.CD_Exception);

    }
}

Output

ClassDesc[ConstantBootstraps] ClassDesc[ConstantDesc] ClassDesc[DirectMethodHandleDesc] PrimitiveClassDesc[double] ClassDesc[Double] ClassDesc[DynamicCallSiteDesc] ClassDesc[DynamicConstantDesc] ClassDesc[Enum] ClassDesc[Enum$EnumDesc] ClassDesc[Exception]


1. ConstantDescs.CD_float

ClassDesc java.lang.constant.ConstantDescs.CD_float

ClassDesc representing the primitive type float

2. ConstantDescs.CD_Float

ClassDesc java.lang.constant.ConstantDescs.CD_Float

ClassDesc representing Float

3. ConstantDescs.CD_int

ClassDesc java.lang.constant.ConstantDescs.CD_int

ClassDesc represents the primitive type int

4. ConstantDescs.CD_Integer

ClassDesc java.lang.constant.ConstantDescs.CD_Integer

ClassDesc representing Integer

5. ConstantDescs.CD_List

ClassDesc java.lang.constant.ConstantDescs.CD_List

ClassDesc representing List

6. ConstantDescs.CD_long

ClassDesc java.lang.constant.ConstantDescs.CD_long

ClassDesc represents the primitive type long

7. ConstantDescs.CD_Long

ClassDesc java.lang.constant.ConstantDescs.CD_Long

ClassDesc representing Long

8. ConstantDescs.CD_Map

ClassDesc java.lang.constant.ConstantDescs.CD_Map

ClassDesc representing Map

9. ConstantDescs.CD_MethodHandle

ClassDesc java.lang.constant.ConstantDescs.CD_MethodHandle

ClassDesc representing MethodHandle

10. ConstantDescs.CD_MethodHandleDesc

ClassDesc java.lang.constant.ConstantDescs.CD_MethodHandleDesc

ClassDesc representing MethodHandleDesc

Approach

Java

package com.ConstantDescs;

import java.lang.constant.ConstantDescs;

public class ConstantDescs4 {
    public static void main(String[] args) {

        System.out.println(ConstantDescs.CD_float);
        System.out.println(ConstantDescs.CD_Float);
        System.out.println(ConstantDescs.CD_int);
        System.out.println(ConstantDescs.CD_Integer);
        System.out.println(ConstantDescs.CD_List);
        System.out.println(ConstantDescs.CD_long);
        System.out.println(ConstantDescs.CD_Long);
        System.out.println(ConstantDescs.CD_Map);
        System.out.println(ConstantDescs.CD_MethodHandle);
        System.out.println(ConstantDescs.CD_MethodHandleDesc);

    }
}

Output

PrimitiveClassDesc[float] ClassDesc[Float] PrimitiveClassDesc[int] ClassDesc[Integer] ClassDesc[List] PrimitiveClassDesc[long] ClassDesc[Long] ClassDesc[Map] ClassDesc[MethodHandle] ClassDesc[MethodHandleDesc]


1. ConstantDescs.CD_MethodHandleDesc_Kind

ClassDesc java.lang.constant.ConstantDescs.CD_MethodHandleDesc_Kind

ClassDesc representing DirectMethodHandleDesc.Kind

2. ConstantDescs.CD_MethodHandles

ClassDesc java.lang.constant.ConstantDescs.CD_MethodHandles

ClassDesc representing MethodHandles

3. ConstantDescs.CD_MethodHandles_Lookup

ClassDesc java.lang.constant.ConstantDescs.CD_MethodHandles_Lookup

ClassDesc representing MethodHandles.Lookup

4. ConstantDescs.CD_MethodType

ClassDesc java.lang.constant.ConstantDescs.CD_MethodType

ClassDesc representing MethodType

5. ConstantDescs.CD_MethodTypeDesc

ClassDesc java.lang.constant.ConstantDescs.CD_MethodTypeDesc

ClassDesc representing MethodTypeDesc

6. ConstantDescs.CD_Number

ClassDesc java.lang.constant.ConstantDescs.CD_Number

ClassDesc representing Number

7. ConstantDescs.CD_Object

ClassDesc java.lang.constant.ConstantDescs.CD_Object

ClassDesc representing Object

8. ConstantDescs.CD_Set

ClassDesc java.lang.constant.ConstantDescs.CD_Set

ClassDesc representing Set

9. ConstantDescs.CD_short

ClassDesc java.lang.constant.ConstantDescs.CD_short

ClassDesc represents the primitive type short

10. ConstantDescs.CD_Short

ClassDesc java.lang.constant.ConstantDescs.CD_Short

ClassDesc representing Short

Approach

Java

package com.ConstantDescs;

import java.lang.constant.ConstantDescs;

public class ConstantDescs5 {
    public static void main(String[] args) {

        System.out.println(ConstantDescs.CD_MethodHandleDesc_Kind);
        System.out.println(ConstantDescs.CD_MethodHandles);
        System.out.println(ConstantDescs.CD_MethodHandles_Lookup);
        System.out.println(ConstantDescs.CD_MethodType);
        System.out.println(ConstantDescs.CD_MethodTypeDesc);
        System.out.println(ConstantDescs.CD_Number);
        System.out.println(ConstantDescs.CD_Object);
        System.out.println(ConstantDescs.CD_Set);
        System.out.println(ConstantDescs.CD_short);
        System.out.println(ConstantDescs.CD_Short);

    }
}

Output

ClassDesc[DirectMethodHandleDesc$Kind] ClassDesc[MethodHandles] ClassDesc[MethodHandles$Lookup] ClassDesc[MethodType] ClassDesc[MethodTypeDesc] ClassDesc[Number] ClassDesc[Object] ClassDesc[Set] PrimitiveClassDesc[short] ClassDesc[Short]


1. ConstantDescs.CD_String

ClassDesc java.lang.constant.ConstantDescs.CD_String

ClassDesc representing String

2. ConstantDescs.CD_Throwable

ClassDesc java.lang.constant.ConstantDescs.CD_Throwable

ClassDesc representing Throwable

3. ConstantDescs.CD_VarHandle

ClassDesc java.lang.constant.ConstantDescs.CD_VarHandle

ClassDesc representing VarHandle

4. ConstantDescs.CD_VarHandleDesc

ClassDesc java.lang.constant.ConstantDescs.CD_VarHandleDesc

ClassDesc representing VarHandleDesc

5. ConstantDescs.CD_void

ClassDesc java.lang.constant.ConstantDescs.CD_void

ClassDesc represents the primitive type void.

6. ConstantDescs.CD_Void

ClassDesc java.lang.constant.ConstantDescs.CD_Void

ClassDesc representing Void

7. DEFAULT_NAME : "_"

String java.lang.constant.ConstantDescs.DEFAULT_NAME : "_"

Invocation name to use when no name is needed, such as the name of a constructor, or the invocation name of a dynamic constant or dynamic callsite when the bootstrap is known to ignore the invocation name.

8. ConstantDescs.FALSE

DynamicConstantDesc<Boolean> java.lang.constant.ConstantDescs.FALSE

Nominal descriptor representing the constant Boolean.TRUE

9. ConstantDescs.TRUE

DynamicConstantDesc<Boolean> java.lang.constant.ConstantDescs.TRUE

Nominal descriptor representing the constant Boolean.TRUE

10. ofCallsiteBootstrap(ClassDesc owner, String name, ClassDesc returnType, ClassDesc... paramTypes)

DirectMethodHandleDesc java.lang.constant.ConstantDescs.ofCallsiteBootstrap(ClassDesc owner, String name, ClassDesc returnType, ClassDesc... paramTypes)

This method takes four arguments. This method returns a MethodHandleDesc corresponding to a bootstrap method for an invoked dynamic callsite, which is a static method whose leading parameter types are Lookup, String, and MethodType.

Parameters: Four parameters are required for this method.

owner: the class declaring the method.

name: the unqualified name of the method.

returnType: the return type of the method.

paramTypes: the types of the static bootstrap arguments, if any.

Returns: the MethodHandleDesc.

Throws:

1. NullPointerException - if any of the arguments are null.

11. ofConstantBootstrap(ClassDesc owner, String name, ClassDesc returnType, ClassDesc... paramTypes)

DirectMethodHandleDesc java.lang.constant.ConstantDescs.ofConstantBootstrap(ClassDesc owner, String name, ClassDesc returnType, ClassDesc... paramTypes)

This method takes four arguments. This method returns a MethodHandleDesc corresponding to a bootstrap method for dynamic constant, which is a static method whose leading arguments are Lookup, String, and Class.

Parameters: Four parameters are required for this method.

owner: the class declaring the method.

name: the unqualified name of the method.

returnType: the return type of the method.

paramTypes: the types of the static bootstrap arguments, if any.

Returns: the MethodHandleDesc.

Throws:

1. NullPointerException - if any of the arguments are null.

Approach

Java

package com.ConstantDescs;

import java.lang.constant.ClassDesc;
import java.lang.constant.ConstantDescs;

public class ConstantDescs6 {
    public static void main(String[] args) {

        System.out.println(ConstantDescs.CD_String);
        System.out.println(ConstantDescs.CD_Throwable);
        System.out.println(ConstantDescs.CD_VarHandle);
        System.out.println(ConstantDescs.CD_VarHandleDesc);
        System.out.println(ConstantDescs.CD_void);
        System.out.println(ConstantDescs.CD_Void);
        System.out.println(ConstantDescs.DEFAULT_NAME);
        System.out.println(ConstantDescs.FALSE);
        System.out.println(ConstantDescs.NULL);
        System.out.println(ConstantDescs.TRUE);
        System.out.println(ConstantDescs.ofCallsiteBootstrap(ClassDesc.of("name"), "name", ClassDesc.of("name"),
                ClassDesc.of("name")));
        System.out.println(ConstantDescs.ofConstantBootstrap(ClassDesc.of("name"), "name", ClassDesc.of("name"),
                ClassDesc.of("name")));

    }
}

Output

ClassDesc[String] ClassDesc[Throwable] ClassDesc[VarHandle] ClassDesc[VarHandle$VarHandleDesc] PrimitiveClassDesc[void] ClassDesc[Void] _ DynamicConstantDesc[ConstantBootstraps::getStaticFinal(FALSE/ClassDesc[Boolean])Boolean] DynamicConstantDesc[ConstantBootstraps::nullConstant()Object] DynamicConstantDesc[ConstantBootstraps::getStaticFinal(TRUE/ClassDesc[Boolean])Boolean] MethodHandleDesc[STATIC/name::name(MethodHandles$Lookup,String,MethodType,name)name] MethodHandleDesc[STATIC/name::name(MethodHandles$Lookup,String,Class,name)name]


Some other classes/interfaces of java.lang.constant

MethodTypeDescA nominal descriptor for a MethodType constant.

MethodHandleDescA nominal descriptor for a MethodHandle constant.

DynamicConstantDescA nominal descriptor for a dynamic constant.

DynamicCallSiteDescA nominal descriptor for an invoke dynamic call site.

DirectMethodHandleDescA nominal descriptor for a direct MethodHandle. A DirectMethodHandleDesc corresponds to a Constant_MethodHandle_info entry in the constant pool of a class file.

ConstantDescsPredefined values of nominal descriptors for common constants, including descriptors for primitive class types and other common platform types, and descriptors for method handles for standard bootstrap methods.

ConstantDescA nominal descriptor for a loadable constant value. Such a descriptor can be resolved via ConstantDesc.resolveConstantDesc(MethodHandles.Lookup) to yield the constant value itself.

ConstableRepresents a type that is constable. A constable type is one whose values are constants that can be represented in the constant pool of a Java class file.

ClassDescA nominal descriptor for a Class constant.

No comments:

Post a Comment