< prev index next >

src/java.base/share/classes/java/lang/Class.java

Print this page

        

*** 57,66 **** --- 57,68 ---- import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.StringJoiner; + import java.util.stream.Stream; + import java.util.stream.Collectors; import jdk.internal.HotSpotIntrinsicCandidate; import jdk.internal.loader.BootLoader; import jdk.internal.loader.BuiltinClassLoader; import jdk.internal.misc.Unsafe;
*** 198,208 **** * The string is formatted as a list of type modifiers, if any, * followed by the kind of type (empty string for primitive types * and {@code class}, {@code enum}, {@code interface}, or * <code>@</code>{@code interface}, as appropriate), followed * by the type's name, followed by an angle-bracketed ! * comma-separated list of the type's type parameters, if any. * * A space is used to separate modifiers from one another and to * separate any modifiers from the kind of type. The modifiers * occur in canonical order. If there are no type parameters, the * type parameter list is elided. --- 200,211 ---- * The string is formatted as a list of type modifiers, if any, * followed by the kind of type (empty string for primitive types * and {@code class}, {@code enum}, {@code interface}, or * <code>@</code>{@code interface}, as appropriate), followed * by the type's name, followed by an angle-bracketed ! * comma-separated list of the type's type parameters, if any, ! * including informative bounds on the type parameters, if any. * * A space is used to separate modifiers from one another and to * separate any modifiers from the kind of type. The modifiers * occur in canonical order. If there are no type parameters, the * type parameter list is elided.
*** 260,283 **** sb.append(getName()); } TypeVariable<?>[] typeparms = component.getTypeParameters(); if (typeparms.length > 0) { ! StringJoiner sj = new StringJoiner(",", "<", ">"); ! for(TypeVariable<?> typeparm: typeparms) { ! sj.add(typeparm.getTypeName()); ! } ! sb.append(sj.toString()); } for (int i = 0; i < arrayDepth; i++) sb.append("[]"); return sb.toString(); } } /** * Returns the {@code Class} object associated with the class or * interface with the given string name. Invoking this method is * equivalent to: * --- 263,294 ---- sb.append(getName()); } TypeVariable<?>[] typeparms = component.getTypeParameters(); if (typeparms.length > 0) { ! sb.append(Stream.of(typeparms).map(t -> typeVarBounds(t)). ! collect(Collectors.joining(",", "<", ">"))); } for (int i = 0; i < arrayDepth; i++) sb.append("[]"); return sb.toString(); } } + String typeVarBounds(TypeVariable<?> typeVar) { + Type[] bounds = typeVar.getBounds(); + if (bounds.length == 1 && bounds[0].equals(Object.class)) { + return typeVar.getName(); + } else { + return typeVar.getName() + " extends " + + Stream.of(bounds).map(e -> e.getTypeName()). + collect(Collectors.joining(" & ")); + } + } + /** * Returns the {@code Class} object associated with the class or * interface with the given string name. Invoking this method is * equivalent to: *
< prev index next >