public sealed interface MethodTypeDesc extends ConstantDesc, TypeDescriptor.OfMethod<ClassDesc,MethodTypeDesc>
一个名义描述符,用于描述一个MethodType常量。
- 自 JDK 版本:
- 12
-
Nested Class Summary
Nested classes/interfaces declared in interface java.lang.invoke.TypeDescriptor
TypeDescriptor.OfField<F extends TypeDescriptor.OfField<F>>, TypeDescriptor.OfMethod<F extends TypeDescriptor.OfField<F>,M extends TypeDescriptor.OfMethod<F, M>> -
Method Summary
Modifier and TypeMethodDescriptionchangeParameterType(int index, ClassDesc paramType) 返回一个与此相同的MethodTypeDesc,只是一个参数类型已更改为指定类型。changeReturnType(ClassDesc returnType) 返回一个与此相同的MethodTypeDesc,只是具有指定的返回类型。返回方法类型描述符字符串。default String返回此方法类型的人类可读描述符,使用参数和返回类型的规范名称。dropParameterTypes(int start, int end) 返回一个与此相同的MethodTypeDesc,只是一系列参数类型已被移除。boolean将指定的对象与此描述符进行比较以检查是否相等。insertParameterTypes(int pos, ClassDesc... paramTypes) 返回一个与此相同的MethodTypeDesc,只是已插入一系列额外的参数类型。static MethodTypeDesc返回一个具有给定返回类型且没有参数类型的MethodTypeDesc。static MethodTypeDesc返回给定返回类型和参数类型的MethodTypeDesc。static MethodTypeDesc返回给定返回类型和参数类型列表的MethodTypeDesc。static MethodTypeDescofDescriptor(String descriptor) 根据方法描述符字符串创建一个MethodTypeDesc。将参数类型作为数组返回。int返回由此MethodTypeDesc描述的方法类型的参数数量。将参数类型作为不可变的List返回。parameterType(int index) 返回由此MethodTypeDesc描述的方法类型的第index个参数类型。获取由此MethodTypeDesc描述的方法类型的返回类型。
-
Method Details
-
ofDescriptor
根据方法描述符字符串创建一个具有给定返回类型且没有参数类型的MethodTypeDesc。- 参数:
-
descriptor- 一个方法描述符字符串 - 返回:
- 描述所需方法类型的MethodTypeDesc
- 抛出:
-
NullPointerException- 如果参数为null -
IllegalArgumentException- 如果描述符字符串不是有效的方法描述符 - 参见 Java 虚拟机规范:
-
4.3.3 方法描述符
-
of
返回一个具有给定返回类型且没有参数类型的MethodTypeDesc。- 参数:
-
returnDesc- 描述返回类型的ClassDesc - 返回:
- 一个具有给定返回类型且没有参数类型的MethodTypeDesc
- 抛出:
-
NullPointerException- 如果returnDesc为null - 自 JDK 版本:
- 21
-
of
返回给定返回类型和参数类型列表的MethodTypeDesc。- 参数:
-
returnDesc- 描述返回类型的ClassDesc -
paramDescs- 描述参数类型的List,其中包含ClassDesc - 返回:
- 给定返回类型和参数类型列表的MethodTypeDesc
- 抛出:
-
NullPointerException- 如果任何参数或其内容为null -
IllegalArgumentException- 如果paramDescs的任何元素是void的ClassDesc - 自 JDK 版本:
- 21
-
of
返回给定返回类型和参数类型的MethodTypeDesc。- 参数:
-
returnDesc- 描述返回类型的ClassDesc -
paramDescs- 描述参数类型的ClassDesc - 返回:
- 描述所需方法类型的MethodTypeDesc
- 抛出:
-
NullPointerException- 如果任何参数或其内容为null -
IllegalArgumentException- 如果paramDescs的任何元素是void的ClassDesc
-
returnType
ClassDesc returnType()获取由此MethodTypeDesc描述的方法类型的返回类型。- 指定者:
-
returnType在接口TypeDescriptor.OfMethod<ClassDesc,中MethodTypeDesc> - 返回:
-
描述方法类型的返回类型的
ClassDesc
-
parameterCount
int parameterCount()返回由此MethodTypeDesc描述的方法类型的参数数量。- 指定者:
-
parameterCount在接口TypeDescriptor.OfMethod<ClassDesc,中MethodTypeDesc> - 返回:
- 参数数量
-
parameterType
返回由此MethodTypeDesc描述的方法类型的第index个参数类型。- 指定者:
-
parameterType在接口TypeDescriptor.OfMethod<ClassDesc,中MethodTypeDesc> - 参数:
-
index- 要检索的参数的索引 - 返回:
-
描述所需参数类型的
ClassDesc - 抛出:
-
IndexOutOfBoundsException- 如果索引超出半开区间[0, parameterCount())
-
parameterList
返回参数类型作为不可变的List。- 指定者:
-
parameterList在接口TypeDescriptor.OfMethod<ClassDesc,中MethodTypeDesc> - 返回:
-
描述参数类型的
List,其中包含ClassDesc
-
parameterArray
ClassDesc[] parameterArray()返回参数类型的数组。- 指定者:
-
parameterArray在接口TypeDescriptor.OfMethod<ClassDesc,MethodTypeDesc> - 返回:
-
一个描述参数类型的
ClassDesc数组
-
changeReturnType
返回一个与此相同的 MethodTypeDesc,只是具有指定的返回类型。- 指定者:
-
changeReturnType在接口TypeDescriptor.OfMethod<ClassDesc,MethodTypeDesc> - 参数:
-
returnType- 描述新返回类型的ClassDesc - 返回:
- 描述所需方法类型的 MethodTypeDesc
- 抛出:
-
NullPointerException- 如果参数为null
-
changeParameterType
返回一个与此相同的 MethodTypeDesc,只是一个参数类型已更改为指定类型。- 指定者:
-
changeParameterType在接口TypeDescriptor.OfMethod<ClassDesc,MethodTypeDesc> - 参数:
-
index- 要更改的参数的索引 -
paramType- 描述新参数类型的ClassDesc - 返回:
- 描述所需方法类型的 MethodTypeDesc
- 抛出:
-
NullPointerException- 如果任何参数为null -
IndexOutOfBoundsException- 如果索引在半开区间[0, parameterCount)之外
-
dropParameterTypes
返回一个与此相同的 MethodTypeDesc,只是一系列参数类型已被移除。- 指定者:
-
dropParameterTypes在接口TypeDescriptor.OfMethod<ClassDesc,MethodTypeDesc> - 参数:
-
start- 要移除的第一个参数的索引 -
end- 要移除的最后一个参数之后的索引 - 返回:
- 描述所需方法类型的 MethodTypeDesc
- 抛出:
-
IndexOutOfBoundsException- 如果start在半开区间[0, parameterCount)之外,或者end在闭区间[0, parameterCount]之外,或者如果start > end
-
insertParameterTypes
返回一个与此相同的 MethodTypeDesc,只是一系列额外的参数类型已被插入。- 指定者:
-
insertParameterTypes在接口TypeDescriptor.OfMethod<ClassDesc,MethodTypeDesc> - 参数:
-
pos- 要插入第一个插入参数的索引 -
paramTypes- 描述要插入的新参数类型的ClassDesc - 返回:
- 描述所需方法类型的 MethodTypeDesc
- 抛出:
-
NullPointerException- 如果任何参数或其内容为null -
IndexOutOfBoundsException- 如果pos在闭区间[0, parameterCount]之外 -
IllegalArgumentException- 如果paramTypes的任何元素是void的ClassDesc
-
descriptorString
String descriptorString()返回方法类型描述符字符串。- 指定者:
-
descriptorString在接口TypeDescriptor - 返回:
- 方法类型描述符字符串
- 参见 Java虚拟机规范:
-
4.3.3 方法描述符
-
displayDescriptor
返回此方法类型的人类可读描述符,使用参数和返回类型的规范名称。- 返回:
- 此方法类型的人类可读描述符
-
resolveConstantDesc
- 指定者:
-
resolveConstantDesc在接口ConstantDesc - API 注意:
- MethodTypeDesc 可以表示不可由 MethodType 表示的方法类型描述符,例如具有超过 255 个参数槽的方法,因此尝试解析这些可能会导致错误。
- 参数:
-
lookup- 提供名称解析和访问控制上下文的MethodHandles.Lookup - 返回:
- 已解析的常量值
- 抛出:
-
ReflectiveOperationException- 如果在解析过程中无法反射解析类、方法或字段
-
equals
将指定对象与此描述符进行比较以检查是否相等。仅当指定对象也是 MethodTypeDesc,二者具有相同的元数,它们的返回类型相等,并且每对对应的参数类型相等时,返回true。
-