< prev index next >

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

Print this page

        

*** 147,157 **** * string "class" or "interface", followed by a space, and then by the * fully qualified name of the class in the format returned by * {@code getName}. If this {@code Class} object represents a * primitive type, this method returns the name of the primitive type. If * this {@code Class} object represents void this method returns ! * "void". * * @return a string representation of this class object. */ public String toString() { return (isInterface() ? "interface " : (isPrimitive() ? "" : "class ")) --- 147,158 ---- * string "class" or "interface", followed by a space, and then by the * fully qualified name of the class in the format returned by * {@code getName}. If this {@code Class} object represents a * primitive type, this method returns the name of the primitive type. If * this {@code Class} object represents void this method returns ! * "void". If this {@code Class} object presents an array type, ! * this method returns "class " followed by {@code getName}. * * @return a string representation of this class object. */ public String toString() { return (isInterface() ? "interface " : (isPrimitive() ? "" : "class "))
*** 172,181 **** --- 173,188 ---- * 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. * + * For an array type, the string starts with the type name, + * followed by an angle-bracketed comma-separated list of the + * type's type parameters, if any, followed by a sequence of + * {@code []} characters, one set of brackets per dimension of + * the array. + * * <p>Note that since information about the runtime representation * of a type is being generated, modifiers not present on the * originating source code or illegal on the originating source * code may be present. *
*** 187,197 **** --- 194,213 ---- public String toGenericString() { if (isPrimitive()) { return toString(); } else { StringBuilder sb = new StringBuilder(); + Class<?> component = this; + int arrayDepth = 0; + if (isArray()) { + do { + arrayDepth++; + component = component.getComponentType(); + } while (component.isArray()); + sb.append(component.getName()); + } else { // Class modifiers are a superset of interface modifiers int modifiers = getModifiers() & Modifier.classModifiers(); if (modifiers != 0) { sb.append(Modifier.toString(modifiers)); sb.append(' ');
*** 208,219 **** else sb.append("class"); } sb.append(' '); sb.append(getName()); ! TypeVariable<?>[] typeparms = getTypeParameters(); if (typeparms.length > 0) { boolean first = true; sb.append('<'); for(TypeVariable<?> typeparm: typeparms) { if (!first) --- 224,236 ---- else sb.append("class"); } sb.append(' '); sb.append(getName()); + } ! TypeVariable<?>[] typeparms = component.getTypeParameters(); if (typeparms.length > 0) { boolean first = true; sb.append('<'); for(TypeVariable<?> typeparm: typeparms) { if (!first)
*** 222,231 **** --- 239,251 ---- first = false; } sb.append('>'); } + for (int i = 0; i < arrayDepth; i++) + sb.append("[]"); + return sb.toString(); } } /**
< prev index next >