< prev index next >

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

Print this page

        

@@ -275,11 +275,12 @@
                 sb.append(Arrays.stream(typeparms)
                           .map(Class::typeVarBounds)
                           .collect(Collectors.joining(",", "<", ">")));
             }
 
-            if (arrayDepth > 0) sb.append("[]".repeat(arrayDepth));
+            for (int i = 0; i < arrayDepth; i++)
+                sb.append("[]");
 
             return sb.toString();
         }
     }
 

@@ -997,11 +998,11 @@
      *
      * @return the fully qualified package name
      *
      * @since 9
      * @spec JPMS
-     * @jls 6.7 Fully Qualified Names
+     * @jls 6.7  Fully Qualified Names
      */
     public String getPackageName() {
         String pn = this.packageName;
         if (pn == null) {
             Class<?> c = this;

@@ -1586,11 +1587,16 @@
                 int dimensions = 0;
                 do {
                     dimensions++;
                     cl = cl.getComponentType();
                 } while (cl.isArray());
-                return cl.getName() + "[]".repeat(dimensions);
+                StringBuilder sb = new StringBuilder();
+                sb.append(cl.getName());
+                for (int i = 0; i < dimensions; i++) {
+                    sb.append("[]");
+                }
+                return sb.toString();
             } catch (Throwable e) { /*FALLTHRU*/ }
         }
         return getName();
     }
 

@@ -3410,16 +3416,19 @@
 
     /**
      * Helper method to get the method name from arguments.
      */
     private String methodToString(String name, Class<?>[] argTypes) {
-        return getName() + '.' + name +
-                ((argTypes == null || argTypes.length == 0) ?
-                "()" :
-                Arrays.stream(argTypes)
-                        .map(c -> c == null ? "null" : c.getName())
-                        .collect(Collectors.joining(",", "(", ")")));
+        StringBuilder sb = new StringBuilder();
+        sb.append(getName() + "." + name + "(");
+        if (argTypes != null) {
+            sb.append(Arrays.stream(argTypes)
+                      .map(c -> (c == null) ? "null" : c.getName())
+                      .collect(Collectors.joining(",")));
+        }
+        sb.append(")");
+        return sb.toString();
     }
 
     /** use serialVersionUID from JDK 1.1 for interoperability */
     private static final long serialVersionUID = 3206093459760846163L;
 

@@ -3908,12 +3917,11 @@
      *         class loader is not the same as or an ancestor of the class
      *         loader for the returned class and invocation of {@link
      *         SecurityManager#checkPackageAccess s.checkPackageAccess()}
      *         denies access to the package of the returned class
      * @since 11
-     * @jvms 4.7.28 The {@code NestHost} Attribute
-     * @jvms 4.7.29 The {@code NestMembers} Attribute
+     * @jvms 4.7.28 and 4.7.29 NestHost and NestMembers attributes
      * @jvms 5.4.4 Access Control
      */
     @CallerSensitive
     public Class<?> getNestHost() {
         if (isPrimitive() || isArray()) {
< prev index next >