@@ -2771,6 +2771,9 @@ private static String toString(final Type type, final Set<Type> done) {
27712771 if (type instanceof WildcardType ) {
27722772 return wildcardTypeToString ((WildcardType ) type , done );
27732773 }
2774+ if (type instanceof CaptureType ) {
2775+ return captureTypeToString ((CaptureType ) type , done );
2776+ }
27742777 if (type instanceof TypeVariable ) {
27752778 return typeVariableToString ((TypeVariable <?>) type , done );
27762779 }
@@ -2944,18 +2947,25 @@ private static String wildcardTypeToString(final WildcardType w,
29442947 final StringBuilder buf = new StringBuilder ().append ('?' );
29452948 if (done .contains (w )) return buf .toString ();
29462949 done .add (w );
2947- final Type [] lowerBounds = w .getLowerBounds ();
2948- final Type [] upperBounds = w .getUpperBounds ();
2949- if (lowerBounds .length > 1 || lowerBounds .length == 1 &&
2950- lowerBounds [0 ] != null )
2951- {
2952- appendAllTo (buf .append (" super " ), " & " , done , lowerBounds );
2953- }
2954- else if (upperBounds .length > 1 || upperBounds .length == 1 &&
2955- !Object .class .equals (upperBounds [0 ]))
2956- {
2957- appendAllTo (buf .append (" extends " ), " & " , done , upperBounds );
2958- }
2950+ appendTypeBounds (buf , w .getLowerBounds (), w .getUpperBounds (), done );
2951+ return buf .toString ();
2952+ }
2953+
2954+ /**
2955+ * Format a {@link CaptureType} as a {@link String}.
2956+ *
2957+ * @param t {@code CaptureType} to format
2958+ * @param done list of already-encountered types
2959+ * @return String
2960+ * @since 3.2
2961+ */
2962+ private static String captureTypeToString (final CaptureType t ,
2963+ final Set <Type > done )
2964+ {
2965+ final StringBuilder buf = new StringBuilder ().append ("capture of ?" );
2966+ if (done .contains (t )) return buf .toString ();
2967+ done .add (t );
2968+ appendTypeBounds (buf , t .getLowerBounds (), t .getUpperBounds (), done );
29592969 return buf .toString ();
29602970 }
29612971
@@ -2970,6 +2980,21 @@ private static String genericArrayTypeToString(final GenericArrayType g) {
29702980 return String .format ("%s[]" , toString (g .getGenericComponentType ()));
29712981 }
29722982
2983+ private static void appendTypeBounds (final StringBuilder buf ,
2984+ final Type [] lowerBounds , final Type [] upperBounds , final Set <Type > done )
2985+ {
2986+ if (lowerBounds .length > 1 || lowerBounds .length == 1 &&
2987+ lowerBounds [0 ] != null )
2988+ {
2989+ appendAllTo (buf .append (" super " ), " & " , done , lowerBounds );
2990+ }
2991+ else if (upperBounds .length > 1 || upperBounds .length == 1 &&
2992+ !Object .class .equals (upperBounds [0 ]))
2993+ {
2994+ appendAllTo (buf .append (" extends " ), " & " , done , upperBounds );
2995+ }
2996+ }
2997+
29732998 /**
29742999 * Append {@code types} to {@code buf} with separator {@code sep}.
29753000 *
0 commit comments