Summary
Add two overloads to MethodTypeDesc.of for user convenience.
Problem
MethodTypeDesc constructor only accepts array as parameters, which is somewhat troublesome for users who want to pass collections or to create types with no parameter.
Solution
Add these two methods: of(ClassDesc) and of(ClassDesc, List), which allows implementation to perform optimizations later.
Specification
(I didn't upload a Javadoc preview for initial version 0, which took a Collection than a List) Version 1: https://cr.openjdk.org/~liach/8306698/1/java.base/java/lang/constant/MethodTypeDesc.html
--- a/src/java.base/share/classes/java/lang/constant/MethodTypeDesc.java
+++ b/src/java.base/share/classes/java/lang/constant/MethodTypeDesc.java
@@ -55,6 +55,34 @@ public sealed interface MethodTypeDesc
return MethodTypeDescImpl.ofDescriptor(descriptor);
}
+ /**
+ * {@return a {@linkplain MethodTypeDesc} with the given return type and no
+ * parameter types}
+ *
+ * @param returnDesc a {@linkplain ClassDesc} describing the return type
+ * @throws NullPointerException if {@code returnDesc} is {@code null}
+ * @since 21
+ */
+ static MethodTypeDesc of(ClassDesc returnDesc) {
+ return new MethodTypeDescImpl(returnDesc, ConstantUtils.EMPTY_CLASSDESC);
+ }
+
+ /**
+ * {@return a {@linkplain MethodTypeDesc} given the return type and a list of
+ * parameter types}
+ *
+ * @param returnDesc a {@linkplain ClassDesc} describing the return type
+ * @param paramDescs a {@linkplain List} of {@linkplain ClassDesc}s
+ * describing the parameter types
+ * @throws NullPointerException if any argument or its contents are {@code null}
+ * @throws IllegalArgumentException if any element of {@code paramDescs} is a
+ * {@link ClassDesc} for {@code void}
+ * @since 21
+ */
+ static MethodTypeDesc of(ClassDesc returnDesc, List<ClassDesc> paramDescs) {
+ return of(returnDesc, paramDescs.toArray(ConstantUtils.EMPTY_CLASSDESC));
+ }
+
/**
* Returns a {@linkplain MethodTypeDesc} given the return type and parameter
* types.
- csr of
-
JDK-8306698 Add overloads to MethodTypeDesc::of
-
- Resolved
-